#include <bits/stdc++.h>
using namespace std;
template <typename T>
void out(T x) {
  cout << x << endl;
  exit(0);
}
const int maxn = 205;
const int inf = 1 << 30;
int a[maxn], n, k;
int dp[maxn][5][15][15];
void init_dp() {
  for (int i = 0; i < maxn; i++) {
    for (int j = 0; j < 5; j++) {
      for (int x = 0; x < 15; x++) {
        for (int y = 0; y < 15; y++) {
          dp[i][j][x][y] = -1;
        }
      }
    }
  }
}
int dfs(int i, int state = 0, int holes = 0, int filled = 0) {
  if (i > n) {
    if (holes == filled && state > 0) return 0;
    return -inf;
  }
  if (dp[i][state][holes][filled] != -1) return dp[i][state][holes][filled];
  int res = -inf;
  if (state == 0) {
    res =
        max(dfs(i + 1, 1, holes, filled) + a[i], dfs(i + 1, 0, holes, filled));
    res = max(res, dfs(i + 1, 1, holes + 1, filled));
    if (filled < k) res = max(res, a[i] + dfs(i + 1, 0, holes, filled + 1));
  } else if (state == 1) {
    res = max(res, a[i] + dfs(i + 1, state, holes, filled));
    if (holes < k) res = max(res, dfs(i + 1, state, holes + 1, filled));
    res = max(res, dfs(i, 2, holes, filled));
  } else if (state == 2) {
    res = max(res, dfs(i + 1, state, holes, filled));
    if (filled < k) res = max(res, a[i] + dfs(i + 1, state, holes, filled + 1));
  }
  return dp[i][state][holes][filled] = res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  init_dp();
  int ans = dfs(1);
  cout << ans << endl;
  return 0;
}
