#include <bits/stdc++.h>
//#define int long long
using namespace std;

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];

    }
    vector<int> b(n);
    vector <int> c;
    for (int i = 0; i < n; ++i) {
        int s = 1;
        for (int j = i - 1; j >= 0; --j) {
            if (a[i] == a[j])
                s++;
        }
        b[i] = s + a[i];
        if (i>0 && a[i]==a[i-1]){
            b[i-1]=a[i-1]+1;
        }
    }
    sort(b.rbegin(), b.rend());
    int ans = 0;
    for (int i = 0; i < k; ++i) {
        ans += b[i];
    }
    cout << ans;
}
