#include <bits/stdc++.h>
using namespace std;
int n, m, h, x, y, s, t, a[512], b[512], c[512];
int main() {
  scanf("%d%d", &n, &m);
  s = -100000000;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    a[n + i] = a[i];
  }
  for (int l = 0; l < n; ++l)
    for (int r = l + 1; r <= n; ++r) {
      t = accumulate(a + l, a + r, 0);
      if (s < t) s = t;
      memmove(b + l, a + l, sizeof(int) * (r - l));
      memmove(c + r, a + r, sizeof(int) * (n + l - r));
      h = min(m, min(r - l, n + l - r));
      for (int i = 0; i < h; ++i) {
        nth_element(b + l, b + l + i, b + r, less<int>());
        nth_element(c + r, c + r + i, c + n + l, greater<int>());
        x = b[l + i];
        y = c[r + i];
        if (x < y)
          s = max(s, t += y - x);
        else
          break;
      }
    }
  printf("%d", s);
  return 0;
}
