#include <bits/stdc++.h>
using namespace std;
int a[300];
int n;
int calc(int l, int r, int k) {
  priority_queue<int> q1, q2;
  for (int i = 0; i < l; ++i) {
    q2.push(a[i]);
  }
  for (int i = l; i <= r; ++i) {
    q1.push(-a[i]);
  }
  for (int i = r + 1; i < n; ++i) {
    q2.push(a[i]);
  }
  int tot = 0;
  int c = r - l + 1;
  for (int i = 0; i < c; ++i) {
    if (q2.empty() || k == 0) {
      tot += (-q1.top());
      q1.pop();
    } else {
      if ((-q1.top()) >= q2.top()) {
        tot += (-q1.top());
        q1.pop();
      } else {
        tot += q2.top();
        q2.pop();
        q1.pop();
        k--;
      }
    }
  }
  return tot;
}
int MAIN() {
  int k;
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
  }
  int best = -1e9;
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      best = max(best, calc(i, j, k));
    }
  }
  printf("%d\n", best);
  return 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(16);
  int ret = MAIN();
  return ret;
}
