#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[205];
  scanf("%d%d", &n, &m);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  int t1[205], t2[205], ans = -999999999;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      int n1 = 0, n2 = 0, tp = 0;
      for (int k = 0; k < i; k++) t1[n1++] = a[k];
      for (int k = j + 1; k < n; k++) t1[n1++] = a[k];
      for (int k = i; k <= j; k++) {
        tp += a[k];
        t2[n2++] = a[k];
      }
      ans = max(ans, tp);
      if (n2 == 0 || n1 == 0) continue;
      sort(t1, t1 + n1);
      sort(t2, t2 + n2);
      int p1 = n1 - 1, p2 = 0;
      for (int k = 1; k <= m; k++) {
        if (p1 < 0 || p2 >= n2) break;
        if (t1[p1] > t2[p2])
          tp += t1[p1] - t2[p2];
        else
          break;
        p1--;
        p2++;
      }
      ans = max(ans, tp);
    }
  }
  printf("%d\n", ans);
  return 0;
}
