n,k=map(int,input().split()) A=[0] for i in list(map(int,input().split())):A=sorted(A+[j+i for j in A])[-k:] print(A[0])