#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[205];
int f[205], rest[205];
int main() {
  int i, j, k, l, ans = -2000000;
  int n1, n2;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (i = 1; i <= n; i++)
    for (j = i; j <= n; j++) {
      n1 = 0;
      for (k = i; k <= j; k++) {
        n1++;
        f[n1] = a[k];
      }
      n2 = 0;
      for (k = 1; k <= i - 1; k++) {
        n2++;
        rest[n2] = a[k];
      }
      for (k = j + 1; k <= n; k++) {
        n2++;
        rest[n2] = a[k];
      }
      sort(f + 1, f + n1 + 1);
      sort(rest + 1, rest + n2 + 1);
      k = 1;
      while (k <= m && k <= n1 && k <= n2 && rest[n2 - k + 1] > f[k]) {
        l = f[k];
        f[k] = rest[n2 - k + 1];
        rest[n2 - k + 1] = l;
        k++;
      }
      l = 0;
      for (k = 1; k <= n1; k++) l += f[k];
      if (l > ans) ans = l;
    }
  printf("%d\n", ans);
  return 0;
}
