// semenInRussia 2025
#pragma GCC optimize("Ofast,unroll-loops")
#include <algorithm>
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
using namespace std;
#pragma GCC target("avx2")

const int N = 100;
int pw[N];

int64_t solve1(vector<int> a, int n, int k) {
  int64_t ans = n;
  for (int i = n - k; i < n; i++) {
    ans += a[i];
  }
  return ans;
}

int64_t solve2(vector<int> a, int n, int k) {
  pw[0] = 1;
  for (int i = 1; i <= n; i++) {
    pw[i] = pw[i - 1] * k;
  }

  int64_t ans = 0;
  vector<int> bst;

  int S = pw[n];

  vector<int> mx(k), sz(k);

  for (int b = 0; b < S; b++) {
    for (int i = 0; i < k; i++) {
      mx[i] = sz[i] = 0;
    }
    for (int j = 0; j < n; j++) {
      int c = (b / pw[j]) % k;
      mx[c] = max(mx[c], sz[c] + 1 + a[j]);
      sz[c]++;
    }
    bool ok = true;
    for (int j = 0; j < k; j++) {
      if (sz[j] == 0) {
        ok = false;
      }
    }
    if (!ok) {
      continue;
    }
    int64_t cost = 0;
    for (auto &row : mx) {
      cost += row;
    }
    ans = max(cost, ans);
  }

  return ans;
}

void stress(int n, int k) {
  vector<int> a(n);
  for (int i = 1; i < n; i++) {
    a[i] = a[i - 1] + (rand() % 1000);
  }
  if (solve1(a, n, k) != solve2(a, n, k)) {
    cerr << "errororr\n";
    cerr << n << ", " << k << endl;
    for (int x : a) {
      cerr << x << " ";
    }
    cerr << endl;
  }
}

int main() {
  int n, k;
  cin >> n >> k;

  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }

  assert(!is_sorted(a.begin(), a.end()));

  cout << solve1(a, n, k) << "\n";
}

int main2() {
  int n = 6;
  int tt = 1e6;
  while (tt--) {
    if (tt % 500'000 == 0) {
      cerr << ".\n";
    }
    int k = rand() % n;
    k++;
    stress(n, k);
  }
  return 0;
}