//KZNS
#include <cstdio>
#include <queue>
#include <vector>
using namespace std;
class cp {
public:
bool operator () (const int a, const int b) {
return a > b;
}
};
int main() {
freopen("waterj.in", "r", stdin);
freopen("waterj.out", "w", stdout);
int N, M;
scanf("%d %d", &N, &M);
priority_queue<int, vector<int>, cp> ls;
for (int i = 0; i < M; i++)
ls.push(0);
int u, a;
for (int i = 0; i < N; i++) {
scanf("%d", &a);
u = ls.top();
ls.pop();
ls.push(u + a);
}
for (int i = 0; i < M; i++) {
u = ls.top();
ls.pop();
}
printf("%d\n", u);
return 0;
}
//UBWH