#include <bits/stdc++.h>
#define rep(i, n) for (int i=0;i<n;i++)
using namespace std;
#define LINF (1LL<<60)
typedef long long ll;

ll n,k,a[20],r=LINF;

int main(){
    cin>>n>>k;rep(i,n)cin>>a[i];
    rep(b,1<<n){
        if (b%2==0||__builtin_popcount(b)!=k)continue;
        ll c=a[0]-1,t=0;
        rep(i,n){
            if (b&(1<<i)){
                if(c>=a[i])c++,t+=c-a[i];
                else c=a[i];
            }
            else c=max(c,a[i]);
        }
        r=min(r,t);
    }
    cout<<r<<'\n';
}