#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m, popcount[32777]; long long a[19];
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> a[i];
long long ret = 1LL << 60;
for (int i = 0; i < 1 << n; i++) {
popcount[i] = popcount[i >> 1] + (i & 1);
if (i % 2 == 0 || popcount[i] < m) continue;
vector<int> b;
for (int j = 0; j < n; j++) {
if (i & (1 << j)) b.push_back(j);
}
b.push_back(n);
long long sum = 0, l = 0;
for (int j = 0; j < b.size() - 1; j++) {
l = max(l + 1, *max_element(a + b[j], a + b[j + 1]));
sum += l - a[b[j]];
}
ret = min(ret, sum);
}
cout << ret << endl;
return 0;
}
I2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8YWxnb3JpdGhtPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwppbnQgbiwgbSwgcG9wY291bnRbMzI3NzddOyBsb25nIGxvbmcgYVsxOV07CmludCBtYWluKCkgewoJY2luID4+IG4gPj4gbTsKCWZvciAoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBjaW4gPj4gYVtpXTsKCWxvbmcgbG9uZyByZXQgPSAxTEwgPDwgNjA7Cglmb3IgKGludCBpID0gMDsgaSA8IDEgPDwgbjsgaSsrKSB7CgkJcG9wY291bnRbaV0gPSBwb3Bjb3VudFtpID4+IDFdICsgKGkgJiAxKTsKCQlpZiAoaSAlIDIgPT0gMCB8fCBwb3Bjb3VudFtpXSA8IG0pIGNvbnRpbnVlOwoJCXZlY3RvcjxpbnQ+IGI7CgkJZm9yIChpbnQgaiA9IDA7IGogPCBuOyBqKyspIHsKCQkJaWYgKGkgJiAoMSA8PCBqKSkgYi5wdXNoX2JhY2soaik7CgkJfQoJCWIucHVzaF9iYWNrKG4pOwoJCWxvbmcgbG9uZyBzdW0gPSAwLCBsID0gMDsKCQlmb3IgKGludCBqID0gMDsgaiA8IGIuc2l6ZSgpIC0gMTsgaisrKSB7CgkJCWwgPSBtYXgobCArIDEsICptYXhfZWxlbWVudChhICsgYltqXSwgYSArIGJbaiArIDFdKSk7CgkJCXN1bSArPSBsIC0gYVtiW2pdXTsKCQl9CgkJcmV0ID0gbWluKHJldCwgc3VtKTsKCX0KCWNvdXQgPDwgcmV0IDw8IGVuZGw7CglyZXR1cm4gMDsKfQ==