#include <bits/stdc++.h>
using namespace std;
const int N = 210;
int a[N], n, k, sum[N];
int mx = -1e9, ans = 0, ed, bestL, bestR, res = -1e9;
vector<int> v1, v2;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
    sum[i] = sum[i - 1] + a[i];
  }
  for (bestL = 1; bestL <= n; bestL++)
    for (bestR = bestL; bestR <= n; bestR++) {
      mx = -1e9;
      ans = sum[bestR] - sum[bestL - 1];
      v1.clear();
      v2.clear();
      for (int i = 1; i <= n; i++) {
        if (i >= bestL && i <= bestR) {
          v1.push_back(a[i]);
        } else {
          v2.push_back(a[i]);
        }
      }
      sort(v1.begin(), v1.end());
      sort(v2.begin(), v2.end());
      reverse(v1.begin(), v1.end());
      int swap = k;
      while (swap && !v1.empty() && !v2.empty() && v1.back() < 0 &&
             v2.back() > 0) {
        swap--;
        ans -= v1.back();
        ans += v2.back();
        v1.pop_back();
        v2.pop_back();
      }
      res = max(res, ans);
    }
  printf("%d\n", res);
  return 0;
}
