#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[222];
void readInput() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
}
int l[222][11];
int r[222][11];
void solve() {
  for (int i = 0; i <= n; i++) {
    l[i][0] = 0;
    for (int j = 1; j <= k; j++) {
      l[i][j] = -1000000000;
      if (i > 0) l[i][j] = max(l[i - 1][j], l[i - 1][j - 1] + a[i]);
    }
  }
  for (int i = n + 1; i >= 1; i--) {
    r[i][0] = 0;
    for (int j = 1; j <= k; j++) {
      r[i][j] = -1000000000;
      if (i <= n) r[i][j] = max(r[i + 1][j], r[i + 1][j - 1] + a[i]);
    }
  }
}
int f[222][11][11];
int ans;
void opt() {
  ans = a[1];
  for (int i = 0; i <= n; i++)
    for (int j1 = 0; j1 <= k; j1++)
      for (int j2 = 0; j2 <= k; j2++) f[i][j1][j2] = -1000000000;
  f[0][0][0] = 0;
  for (int i = 1; i <= n; i++) {
    for (int j1 = 0; j1 <= k; j1++)
      for (int j2 = 0; j2 <= k; j2++) {
        f[i][j1][j2] = a[i] + f[i - 1][j1][j2];
        if (j1 == 0) f[i][j1][j2] = max(f[i][j1][j2], a[i] + l[i - 1][j2]);
        if (j1 == 1) f[i][j1][j2] = max(f[i][j1][j2], l[i - 1][j2]);
        if (j1 >= 1) f[i][j1][j2] = max(f[i][j1][j2], f[i - 1][j1 - 1][j2]);
        if (j1 >= j2) {
          ans = max(ans, f[i][j1][j2] + r[i + 1][j1 - j2]);
        }
      }
  }
}
int main() {
  if (0 == 1) {
    freopen("input.txt", "r", stdin);
  }
  readInput();
  solve();
  opt();
  cout << ans << endl;
  return 0;
}
