#include <bits/stdc++.h>
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<ii>
#define all(v) v.begin(), v.end()
#define pb push_back
#define ln << '\n'
#define int long long
using namespace std;

const int N = 5e5 + 22;
int n, k, a[N], an[N], ku[N];
int ans = 0;
vi v, kuk[N];

void solve() {
    for (int i = 0; i < k; i++) an[i] = 0, ku[i] = 0;
    for (int i = 0; i < n; i++) {
        ku[v[i]]++;
        an[v[i]] = max(an[v[i]], a[i] + ku[v[i]]);
    }
    int preans = 0;
    for (int i = 0; i < k; i++) preans += an[i];
    ans = max(ans, preans);
}

int32_t main() {
    cin.tie(0); cout.tie(0); ios::sync_with_stdio(0);
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    // int cur = 0;
    // for (int i = 0; i < n; i++) {
    //     v.pb(cur);
    //     cur++; cur %= k;
    // }
    //
    // sort(all(v));
    // solve();
    // while (next_permutation(all(v))) {
    //     solve();
    // }

    int cur = 0;
    reverse(a + 1, a + n + 1);
    for (int i = 1; i <= n; i++) {
        kuk[cur].pb(a[i]);

        cur++;
        cur %= k;
    }
    int ans = 0;
    for (int i = 1; i <= k; i++) {
        ans += kuk[i][0] + kuk[i].size();
    }

    cout << ans;
    return 0;
}