#include <bits/stdc++.h>
using namespace std;
const long long N = 209;
int a[N];
int n, k;
int f() {
  int mx = -1000 * 1000;
  int nw = 0;
  for (int i = 0; i < int(n); ++i) {
    nw += a[i];
    mx = max(mx, nw);
    if (nw < 0) nw = 0;
  }
  return mx;
}
int main() {
  cin >> n >> k;
  for (int i = 0; i < int(n); ++i) cin >> a[i];
  int mx = -1000 * 1000;
  int ans = f();
  int il, ir;
  for (int l = 0; l < int(n); ++l)
    for (int r = l; r < n; ++r) {
      int sum_in = 0, sum_out = 0;
      vector<int> a1, a2;
      for (int i = 0; i < int(n); ++i)
        if (i <= r && i >= l)
          a1.push_back(a[i]);
        else
          a2.push_back(a[i]);
      int nw = 0;
      for (int i = l; i <= r; ++i) nw += a[i];
      sort(a1.begin(), a1.end());
      sort(a2.begin(), a2.end());
      reverse(a2.begin(), a2.end());
      int pos = min(a1.size(), a2.size());
      pos = min(pos, k);
      for (int i = 0; i < pos; ++i) {
        if (a1[i] < a2[i]) sum_in += a1[i], sum_out += a2[i];
      }
      ans = max(ans, nw + sum_out - sum_in);
    }
  cout << ans;
}
