#include <bits/stdc++.h>
#include <bits/extc++.h>

#pragma GCC target("avx2")
#ifndef ABOBA
#pragma GCC optimize("O3")
#endif

using namespace std;
using namespace __gnu_pbds;

using ll = long long;
using ld = long double;
using ull = unsigned long long;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ll inf = 1e18, mod = 1e9 + 7;

void solve() {
    ll n, k, maxx = 0;
    cin >> n >> k;
    vector<pair<ll, ll>> a(n);
    vector<ll> used(n);
    for (ll i = 0; i < n; ++i) {
        cin >> a[i].first;
        a[i].second = i;
    }
    for (ll tmp = 1; tmp <= 5; ++tmp) {
        for (ll i = 0; i < n; ++i) {
            a[i].first += a[i].second / tmp;
        }
        std::sort(a.rbegin(), a.rend());
        vector<vector<ll>> ans(k);
        for (ll i = 0; i < k; ++i) {
            used[a[i].second] = 1;
        }
        for (ll i = 0; i < k; ++i) {
            for (ll j = 0; j < a[i].second; ++j) {
                if (!used[j]) {
                    ans[i].emplace_back(j);
                    used[j] = 1;
                }
            }
        }
        ll ans1 = 0;
        for (ll i = 0; i < k; ++i) {
            ans1 += a[i].first - a[i].second / tmp + ans[i].size() + 1;
        }
        for (ll i = 0; i < n; ++i) {
            a[i].first -= a[i].second / tmp;
        }
        maxx = max(maxx, ans1);
    }
    cout << maxx;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll tt = 1;
    while (tt--) solve();
}