#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define int ll

void solve() {

  int n,k; cin >> n >> k;
  int a[n]; for(int &i : a) cin >> i;


  int ans = 0;
  int col[n]; memset(col, 0, sizeof col);
  while(1) {
    int mx[k]; memset(mx, -1, sizeof mx);
    int cnt[k]; memset(cnt, 0, sizeof cnt);
    
    for(int i = 0; i < n; ++i) {
      cnt[col[i]]++;
      mx[col[i]] = max(mx[col[i]], a[i]+cnt[col[i]]);
    }

    int res = 0; bool ok = 1;
    for(int i = 0; i < k; ++i) {
      res += mx[i];
      ok &= (col[i] > 0);
    }


    ans = max(ans, res);

    col[0]++;
    for(int i = 0; i < n-1; ++i) {
      if(col[i] == k) col[i+1]++;
      col[i] %= k;
    }
    if(col[n-1] == k) break;
  }

  cout << ans << '\n';

  return;
}


signed main() {
  ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef pcms2
  freopen(".in", "r", stdin);
  freopen(".out", "w", stdout);
#endif
  // int tt; cin >> tt; while(tt--)
  solve();

  return 0;
}