#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define endl '\n'
#define int long long
#define F first
#define S second
#define pii pair<int, int>
#define pic pair<int, char>
#define pci pair<char, int>
#define psi pair<string, int>
#define pis pair<int, string>
#define pipii pair<int, pair<int, int>>
#define piipi pair<pair<int, int>, int>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes() cout << "Yes" << endl
#define no() cout << "No" << endl
int dx[] = {2, 2, 1, 1, -1, -1, -2, -2};
int dy[] = {1, -1, -2, 2, -2, 2, -1, 1};
const int INF = 1e18;
const int MOD = 1e9 + 7;
template<typename T>
using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T>
using ordered_multiset = tree<pair<T,int>, null_type, less<pair<T,int>>, rb_tree_tag, tree_order_statistics_node_update>;
signed main() {
// freopen("input.txt","r",stdin);
// freopen("output.txt","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, k;
cin >> n >> k;
int arr[n];
for(int i = 0;i < n;i++) cin >> arr[i];
int ans = INF;
for(int mask = 0;mask < (1 << n);mask++){
vector<pii> vt;
int l = -1, r = -1;
if(!(mask & (1 << 0))) continue;
for(int i = 0;i < n;i++){
if(mask & (1 << i)){
if(l != -1) vt.push_back({l, r});
l = i, r = i;
}
else r++;
}
vt.push_back({l, r});
if(vt.size() != k) continue;
int cost = 0;
for(auto &[l, r] : vt) cost += arr[r] - arr[l] + 1;
ans = min(ans, cost);
}
cout << ans << endl;
}