# coding: utf-8 # Your code here! N,K=map(int,input().split()) A=list(map(int,input().split())) solves=[0] for a in A: temp=[] for solve in solves: temp.append(solve-a) solves+=temp solves.sort() solves=solves[:K] print(-solves[-1])