//------------------------------------------------------------
#define MOD 1000000007

//------------------------------------------------------------
#if 1
#include <bits/stdc++.h>
using namespace std;

//------------------------------------------------------------
using ll = long long;
#define int ll

#define FOR(i, s, e) for (ll i = ll(s); i < (ll)e; ++i)
#define RFOR(i, s, e) for (ll i = ll(e) - 1; i >= ll(s); --i)
#define REP(i, n) for (ll i = 0, i##_size = (ll)n; i < i##_size; ++i)
#define RREP(i, n) for (ll i = ll(n) - 1; i >= 0; --i)

//------------------------------------------------------------
template <class T>
struct arr : public vector<T> {
	arr() {}
	arr(ll n, T v = T()) : vector<T>(n, v) {}
	void init(ll n, T v = T()) {
		this->clear();
		this->resize(n, v);
	}
	ll sz() const { return (ll)this->size(); }
	void pb(T v) { this->push_back(v); }
	void sort() { std::sort(this->begin(), this->end()); }
	void rsort() { std::sort(this->begin(), this->end(), greater<T>()); }
	void uniqueErase() {
		this->erase(std::unique(this->begin(), this->end()), this->end());
	}
};
using ints = arr<ll>;
using intss = arr<arr<ll>>;

template <class T>
struct que : public queue<T> {
	ll sz() const { return (ll)this->size(); }
	T popfront() {
		T v = this->front();
		this->pop();
		return v;
	}
};

template <class A, class B>
struct pr {
	union {
		A a;
		A key;
		A first;
		A x;
	};
	union {
		B b;
		B value;
		B second;
		B y;
	};

	pr() : a(A()), b(B()) {};
	pr(A a_, B b_) : a(a_), b(b_) {}
	pr(pr const& r) : a(r.a), b(r.b) {};
	pr(pair<A, B> const& r) : a(r.first), b(r.second) {};

	bool operator == (pr const& r) const {
		return a == r.a && b == r.b;
	}
	bool operator != (pr const& r) const {
		return !((*this) == r);
	}
	bool operator < (pr const& r) const {
		if (a == r.a) {
			return b < r.b;
		}
		return a < r.a;
	}

	pr operator + (pr v) const { return pr(x, y) += v; }
	pr operator - (pr v) const { return pr(x, y) -= v; }

	pr& operator += (pr v) {
		x += v.x;
		y += v.y;
		return *this;
	}
	pr& operator -= (pr v) {
		x -= v.x;
		y -= v.y;
		return *this;
	}

	friend istream& operator>>(istream& is, pr& p) {
		is >> p.a >> p.b;
		return is;
	}
};
using pint = pr<ll, ll>;
using pints = arr<pint>;

template <class K, class V>
struct dic : public map<K, V> {
	bool get(K const& k, V* v) {
		auto it = this->find(k);
		if (it != this->end()) {
			*v = it->second;
			return true;
		}
		return false;
	}
};

template <class T>
struct arr2 {
	vector<vector<T>> vec;

	arr2() {}
	arr2(int w, int h, T const& value = T()) { vec.resize(h, vector<T>(w, value)); }
	arr2(arr2 const& r) { vec = r.vec; }
	arr2(arr2&& r) { vec = move(r.vec); }
	arr2& operator=(arr2 const& r) { vec = r.vec; return *this; }
	arr2& operator=(arr2&& r) { vec = move(r.vec); return *this; }

	int width() const { return (int)vec[0].size(); }
	int height() const { return (int)vec.size(); }

	void init(int w, int h, T const& value = T()) {
		vec.clear();
		vec.resize(h, vector<T>(w, value));
	}
	T& operator()(int x, int y) { return vec.at(y).at(x); }
	T const& operator()(int x, int y) const { return vec.at(y).at(x); }

	T& operator()(pint p) { return vec.at(p.y).at(p.x); }
	T const& operator()(pint p) const { return vec.at(p.y).at(p.x); }
};

//------------------------------------------------------------
template <class T> void chmin(T& a, T b) { if (b < a) { a = b; } }
template <class T> void chmax(T& a, T b) { if (b > a) { a = b; } }

constexpr int gcd(int a, int b) {
	if (a < 0) { a = -a; }
	if (b < 0) { b = -b; }
	if (a == 0) { return b; }
	if (b == 0) { return a; }

	while (int c = a % b) {
		a = b;
		b = c;
	}
	return b;
}

//------------------------------------------------------------
struct bfs {
	ints froms;
	ints steps;

	bfs(int N, intss const& adjacency) {
		froms.init(N, -1);
		steps.init(N, -1);

		que<ll> queue;
		queue.push(0);
		froms[0] = 0;
		steps[0] = 0;

		while (queue.empty() == false) {
			ll p = queue.popfront();

			for (ll n : adjacency[p]) {
				if (froms[n] != -1) {
					continue;
				}

				froms[n] = p;
				steps[n] = steps[p] + 1;
				queue.push(n);
			}
		}
	}
};

//------------------------------------------------------------
template <int M>
struct modint {
	int raw;

	modint() { raw = 0; }
	modint(int v) {
		if (v < 0) {
			raw = (v % M) + M;
		}
		else if (v >= M) {
			raw = v % M;
		}
		else {
			raw = v;
		}
	}
	modint operator + (modint v) const { return modint(raw) += v; }
	modint operator - (modint v) const { return modint(raw) -= v; }
	modint operator * (modint v) const { return modint(raw) *= v; }

	modint& operator += (modint v) {
		raw += v.raw;
		if (raw >= M) { raw -= M; }
		return *this;
	}
	modint& operator -= (modint v) {
		raw -= v.raw;
		if (raw < 0) { raw += M; }
		return *this;
	}
	modint& operator *= (modint v) {
		raw = (raw * v.raw) % M;
		return *this;
	}
	modint pow(int n) const {
		return modint::pow(raw, n);
	}
	static modint pow(int a, int n) {
		if (n < 0) {
			// not support
			abort();
		}

		int r = 1;
		while (n) {
			if (n & 1) {
				r = (r * a) % M;
			}
			a = (a * a) % M;
			n >>= 1;
		}
		return modint(r);
	}

	friend istream& operator>>(istream& is, modint& m) {
		int v;
		is >> v;
		m = modint(v);
		return is;
	}
	friend ostream& operator<<(ostream& os, modint const& m) {
		return os << m.raw;
	}
};

using mint = modint<MOD>;
using mints = arr<mint>;

//------------------------------------------------------------
#if defined(TEST)
extern istream& myInputStream;
extern ostream& myOutputStream;
#else
istream& myInputStream = cin;
ostream& myOutputStream = cout;
#endif

struct input_base {
	template <class T>
	static T exec() {
		T var;
		myInputStream >> var;
		return var;
	}

	operator int() { return input_base::exec<int>(); }
	operator string() { return input_base::exec<string>(); }

	template <class K, class V>
	operator pr<K, V>() { return input_base::exec<pr<K, V>>(); }

	template <class K, class V>
	operator pair<K, V>() {
		pair<K, V> p;
		p.first = input_base::exec<K>();
		p.second = input_base::exec<V>();
		return p;
	}
};

struct inputs {
	ll n;
	inputs(ll n_) : n(n_) {}

	template <class T>
	operator arr<T>() {
		arr<T> var(n);
		REP(i, n) {
			var[i] = input_base();
		};
		return var;
	}

	template <class K, class V>
	operator dic<K, V>() {
		dic<K, V> var;
		REP(i, n) {
			pair<K, V> p = input_base();
			var.insert(p);
		};
		return var;
	}
};

struct input {
	operator int() { return input_base(); }
	operator string() { return input_base(); }

	template <class K, class V>
	operator pr<K, V>() { return input_base(); }

	template <class K, class V>
	operator pair<K, V>() { return input_base(); }

	inputs operator()(int n) {
		return inputs(n);
	}

} input;

template <class T>
void output(T var) {
	myOutputStream << (var) << '\n';
}

template <class H, class... T>
void output(H&& head, T&&... tail)
{
	myOutputStream << head << " ";
	output(forward<T>(tail)...);
}

//------------------------------------------------------------
#if defined(TEST)
#include "test.hpp"
#else
void myMain();
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(16);
	myMain();
	return 0;
}
#endif
#endif

//------------------------------------------------------------

void myMain() {
	int N = input;
	int K = input;
	ints a = input(N);

	int minCost = INT64_MAX;
	int size = pow(2, N);
	REP(i, size) {
		int h = 0;
		int cost = 0;
		int cnt = 0;
		REP(j, N) {
			if ((i >> j) & 1) {
				++cnt;
				if (cnt > K) {
					break;
				}
				if (h < a[j]) {
					h = a[j];
				}
				else {
					cost += (h - a[j]) + 1;
					h += 1;
				}
			}
			else {
				chmax(h, a[j]);
			}
		}
		if (cnt != K) {
			continue;
		}
		chmin(minCost, cost);
	}

	output(minCost);
}

Measured memory_bytes: 256