#include <bits/stdc++.h>

using namespace std;
#define int long long
using pii = pair<int, int>;


/*void build(int v, int tl, int tr){
    if (tl == tr){
        t[v] = a[tl];
        return;
    }

    int tm = (tl + tr) / 2;
    build(v * 2, tl, tm);
    build(v * 2 + 1, tm + 1, tr);
    t[v] = t[v * 2] + t[v * 2 + 1];
    return;
}*/

/*

int get_sum(int v, int tl, int tr, int l, int r){
    if (r < l){
        return 0;
    }
    if (tl == l && tr == r){
        return t[v];
    }

    int tm = (tl + tr) / 2;
    return get_sum(v * 2, tl, tm, l, min(r, tm)) + get_sum(v * 2, tm + 1, tr, max(tl, tm + 1), tr);
}

void upd(int v, int tl, int tr, int pos, int val){
    if (tl == tr) {
        t[v] += val;
        return;
    }
    int tm = (tl + tr) / 2;
    if (tm <= pos){
        upd(v * 2, tl, tm, pos, val);
    }
    else{
        upd(v * 2 + 1, tm + 1, tr, pos, val);
    }
    t[v] = t[v * 2] + t[v * 2 + 1];
    return;
}
*/

// priority_queue <pii, vector <pii>, greater<>> q;

int inf = 1e18;


int solve_good(int n, int k, vector <int> a){
    int ans = 0;
    int mx = 0;
    int plus = 0;
    int p = 0;
    for (int j = 0; j < k; j++) {
        mx = 0;
        int p_mx = 0;
        bool flag = false;
        int pos = 0;
        for (int i = 0; i < n; i++) {
            if (i >= p && !flag){
                flag = true;
                pos = i;
            }

            if (flag){
                if (mx < a[i] + i + 1) {
                    mx = a[i] + i + 1 - pos;
                    p_mx = i + 1;
                }
            }
            else{
                if (mx < a[i]) {
                    mx = a[i];
                    p_mx = i + 1;
                }
            }
        }
        ans += mx;
        p = max(p_mx, p);
        a[p_mx - 1] = -inf;
    }

    if (ans > 10){
        a[-1] = 1;
    }
    return ans;
}

int solve_bad(int n, int k, vector <int> a) {
    int ans = k;

    for (int i = 0; i < k; i++){
        ans += a[i];
    }
    return ans;
}


signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int tt = 1;
    // cin >> tt;
    while (tt--) {
        int n, k;
        cin >> n >> k;
        vector <int> a(n);
        for (int i = 0; i < n; i++){
            cin >> a[i];
        }
        cout << solve_good(n, k, a) << '\n';
    }
    return 0;
}


