#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#pragma GCC optimize("Ofast")

using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using ld = long double;

ll inf = (ll)1e18;

template<class T>
ll len(T& a) {
    return (ll)a.size();
}

void solve() {
    ll n, k;
    cin >> n >> k;

    vector<ll> a(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i];
    }

    ll res = 0;
    for (ll i = k-1; i < n; ++i) {
        vector<ll> temp = {a.begin(), a.begin() + i};
        sort(temp.rbegin(), temp.rend());
        ll curr = 0;
        for (ll j = 0; j < k-1; ++j) {
            curr += temp[j];
        }
        res = max(res, a[i] + i + 1 + curr);
    }
    cout << res << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    solve();

    return 0;
}