#include <bits/stdc++.h>
using namespace std;
const int inf = 0x3f3f3f3f;
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  vector<int> A(n), acc(n);
  for (int i = (0); i < (n); ++i) cin >> A[i];
  acc[0] = A[0];
  for (int i = (1); i < (n); ++i) acc[i] = A[i] + acc[i - 1];
  int rsp = -inf;
  for (int i = (0); i < (n); ++i) {
    for (int j = (i); j < (n); ++j) {
      int sum = acc[j] - (i ? acc[i - 1] : 0);
      rsp = max(rsp, sum);
      vector<int> v1, v2;
      for (int kk = (0); kk < (n); ++kk) {
        if (kk < i or kk > j) {
          v1.push_back(A[kk]);
        } else {
          v2.push_back(A[kk]);
        }
      }
      sort(v1.rbegin(), v1.rend());
      sort(v2.begin(), v2.end());
      int lim = min(v1.size(), v2.size());
      for (int kk = (0); kk < (min(k, lim)); ++kk) {
        sum -= v2[kk];
        sum += v1[kk];
        rsp = max(rsp, sum);
      }
    }
  }
  printf("%d\n", rsp);
  return 0;
}
