#include <cstdint>
#include <functional>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
using ll = int64_t;

ll n,m;
priority_queue<ll, vector<ll>,greater<>> list_pq;

int main(){
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
    cin>>n>>m;
    for(ll i{1};i<=m;i++){
        list_pq.emplace(0);
    }
    while(n--){
        ll tmp;
        cin>>tmp;
        ll front{list_pq.top()};
        list_pq.pop();
        front+=tmp;
        list_pq.emplace(front);
    }
    ll ans{};
    while(list_pq.size()){
        ans=list_pq.top();
        list_pq.pop();
    }
    cout<<ans<<'\n';
}