
#include<bits/stdc++.h>

#define int long long
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin() , x.rend()
#define f first
#define second

using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using pi = pair<int , int>;
using vpi = vector<pi>;


const int mod = 1e9 + 7;

ll summ(int a , int b , const int &mod) {
    return ((a + b) % mod + mod) % mod;
}
ll mn(int a , int b , const int &mod) {
    return ((a - b) % mod + mod) % mod;
}
ll umn(int a , int b , const int &mod) {
    return ((a * b) % mod + mod) % mod;
}
int binpow(int a , int p) {
    if (p == 0) return 1;
    if (p & 1) {
        return umn(a , binpow(a , p - 1) , mod);
    } else {
        int x = binpow(a , p / 2);
        return umn(x , x , mod);
    }
}

int del(int a , int b , const int &mod) {
    return umn(a , binpow(b , mod - 2) , mod);
}

struct node {
    int ans , cnt , mx , pos;
};
bool operator<(const node a , const node b) {
    return ((a.mx == b.mx ? a.pos < b.pos : a.mx < b.mx));
}

struct pope {
    int x , ind;
};
int inf = 2e9;


struct sg {
    vector<pope> tree;
    pope comp(pope a , pope b) {
        if(a.x > b.x) {
            return a;
        }
        if(a.x < b.x) {
            return b;
        }
        return {a.x , max(a.ind , b.ind)};
    }
    void build(vector<int> &arr ,int num , int vl , int vr) {
        if(vl + 1 == vr) {
            tree[num] = {arr[vl] , vl};
        } else {
            int vm = (vl + vr) / 2;
            build(arr, num * 2 + 1 , vl , vm);
            build(arr, num * 2 + 2 , vm , vr);
            tree[num] = comp(tree[num * 2 + 1] , tree[num * 2 + 2]);
        }
    }
    pope get (int num , int vl , int vr  , int l , int r) {
        if (l <= vl && vr <= r) {
            return tree[num];
        }
        if (vr <= l || r <= vl) {
            return {0  , -1};
        }
        int vm = (vl + vr) / 2;
        return comp(get(num * 2 + 1 , vl , vm , l , r) , get(num * 2 + 2 , vm , vr , l , r));
    }
    void upd(int num , int vl , int vr , int pos , pope x) {
        if(vl + 1 == vr) {
            tree[num] = x;
        } else {
            int vm = (vl + vr) / 2;
            if(pos < vm) {
                upd(num * 2 + 1 , vl , vm , pos , x);
            } else {
                upd(num * 2 + 2 , vm , vr , pos , x);
            }
            tree[num] = comp(tree[num * 2 + 1] , tree[num * 2 + 2]);
        }
    }
};

void solve() {
    int n , k;
    cin >> n >> k;
    vector<int> a(n);
    vector<node> st;
    int sum = 0;
    vector<int> p1(n) , p2(n);
    for(int i = 0 ; i < n ; i++) {
        cin >> a[i];
        if(i == 0) {
            p1[i] = a[i] + 1;
        } else {
            p1[i] = max(p1[i - 1] , a[i] + i + 1);
        }
    }
    reverse(all(a));
    int ans = 0 , j = n - 1;
    for(int i = 0 ; i < k - 1 ; i++) {
        ans += a[j--] + 1;
    }
    cout << ans + a[j] + (n - k + 1);
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    solve();
}


