#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <complex>
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define pb push_back
#define ins insert
#define C complex<double>
#define X real()
#define Y imag()
using ll = long long;
using namespace std;

struct segtree {
	int size = 4;
	vector<ll> tree;

	void init(int k) {
		while (size < k) size *= 2;
		tree.assign(size, 0);
	}

	void set(int a, int b, ll k) {
		a += size; b += size;

	}

	ll get(int k) {

	}
};

int main(){
	int n, k; cin >> n >> k;
	vector<int> a(n), b(n);
	for (auto& e : a)cin >> e;
	multiset<pair<int,int>, greater<pair<int,int>>> ms;
	multiset<pair<int,int>> m;
	for (int i = 0; i < n;i++) {
		ms.insert({a[i],i});
	}
	for (auto e : ms) {
		m.ins(e);
		k--;
		if (!k) break;
	}
	ll s = 0;
	for (auto e : m) {
		s += e.first + 1ll;
		b[e.second] = 1;
	}
	/*cout << s << endl;
	for (auto e : b) cout << e << ' '; cout << endl;*/
	for (auto e : m) {
		ll mx = e.first+1ll, c=0, ind=-1;
		for (int i = 0; i < n; i++) {
			if (!b[i] || i==e.second) {
				c++;
				if (a[i] + c > mx) {
					mx = a[i] + c;
					ind = i;
				}
			}
		}
		if (ind!=-1) {
			s += mx - e.first - 1;
			for (int i = 0; i <= ind; i++) {
				if (!b[i]) b[i] = 1;
			}
			/*for (auto e : b) cout << e << ' ';
			cout << endl;
			cout << e.first << ' ' << mx << endl;*/
		}
	}
	cout << s << endl;
}