#include <iostream>
#include <vector>
#include <algorithm>
#include <set>

using namespace std;
#define int long long
signed main() {
    int n, k;
    cin >> n >> k;
    vector <int> a(n);
    for (int &i : a)  cin >> i;
    int ans = 0;
    for (int i = 0; i < (1 << n); ++i) {
        if (__builtin_popcount(i) == k) {
            int x = -1, c = 0;
            for (int j = n - 1; j >= 0; --j) {
                if (i & (1 << j)) {
                    x = max(x, a[j]);
                    c += a[j] + 1;
                } else
                if (a[j] < x) {
                    c++;
                }
            }
            ans = max(ans, c);
        }
    }
    cout << ans;
    return 0;
}
