#include <bits/stdc++.h>
using namespace std;
int n, k;
long long sum = 0, a[1005];
long long cnt = 0, v[1000005];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++)
    scanf("%lld", &a[i]), sum += a[i], v[cnt++] = a[i];
  ;
  for (int i = 2; i <= n; i++) a[i] += a[i - 1];
  a[0] = 0;
  for (int i = 1; i <= n; i++)
    for (int j = i + 1; j <= n; j++) v[cnt++] = a[j] - a[i - 1];
  sort(v, v + cnt);
  printf("%lld\n", v[cnt - k]);
}
