#include <bits/stdc++.h>
using namespace std;
const int maxn = 1001000;
const int maxm = 1000100;
const int INF = 0x3f3f3f3f;
const int mod = 1000000007;
int n, m;
int a[maxn];
int b[maxn];
int c[maxn];
int sum[maxn];
int main() {
  int i, j;
  int k;
  scanf("%d%d", &n, &m);
  sum[0] = 0;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  int ans = -INF;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j++) {
      int cntb = 0;
      int cntc = 0;
      for (k = 1; k <= n; k++) {
        if (k >= i && k <= j) {
          b[cntb++] = a[k];
        } else {
          c[cntc++] = a[k];
        }
      }
      sort(b, b + cntb);
      sort(c, c + cntc);
      int cnt = min(cntb, cntc);
      int temp = sum[j] - sum[i - 1];
      for (k = 0; k < cnt && k < m; k++) {
        if (b[k] < c[cntc - 1 - k]) {
          temp += c[cntc - 1 - k] - b[k];
        }
      }
      ans = max(ans, temp);
    }
  }
  printf("%d\n", ans);
  return 0;
}
