#include <bits/stdc++.h>
using namespace std;
int n, m, t, a[250], p[250], q[250], x, y, v = -1000000000, s;
inline int minest(int a, int b, int c) {
  if (a <= b && a <= c) return a;
  if (b <= a && b <= c) return b;
  return c;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= n; i++)
    for (int j = i; j <= n; j++) {
      x = y = s = 0;
      for (int k = 1; k <= n; k++)
        if (k >= i && k <= j)
          x++, p[x] = a[k];
        else
          y++, q[y] = a[k];
      sort(q + 1, q + y + 1);
      sort(p + 1, p + x + 1);
      t = minest(x, y, m);
      for (int k = t + 1; k <= x; k++) s += p[k];
      x = t;
      for (int k = y; k >= y - t + 1; k--) x++, p[x] = q[k];
      sort(p + 1, p + x + 1);
      for (int k = 0; k < t; k++) s += p[x - k];
      if (s > v) v = s;
    }
  cout << v << endl;
  return 0;
}
