#include <bits/stdc++.h>
using namespace std;
int n, k, a[222];
int main() {
  int i, j, x, ankap = -10000;
  bool b = false;
  scanf("%d%d", &n, &k);
  for (i = 0; i < n; ++i) {
    scanf("%d", a + i);
    if (a[i] >= 0) b = true;
    if (a[i] > ankap) ankap = a[i];
  }
  if (!b) {
    cout << ankap << endl;
    return 0;
  }
  multiset<int> v;
  multiset<int> v0;
  multiset<int>::iterator it1;
  multiset<int>::iterator it0;
  int ans = -10000;
  int k0 = k;
  int j0;
  for (i = 0; i < n; ++i) {
    int s = 0;
    int maxs = -10000, maxj;
    for (j0 = i; j0 < n; ++j0) {
      s += a[j0];
      maxs = s;
      maxj = j0;
      for (j = i; j <= maxj; ++j) {
        if (a[j] < 0) v0.insert(-a[j]);
        if (v0.size() > k) v0.erase(v0.begin());
      }
      for (j = 0; j < i; ++j) {
        if (a[j] > 0) v.insert(a[j]);
        if (v.size() > k) v.erase(v.begin());
      }
      for (j = maxj + 1; j < n; ++j) {
        if (a[j] > 0) v.insert(a[j]);
        if (v.size() > k) v.erase(v.begin());
      }
      it0 = v0.begin();
      it1 = v.begin();
      for (j = 0; j < v.size(); ++j) {
        maxs += *it1;
        it1++;
      }
      for (j = 0; j < v0.size(); ++j) {
        maxs += *it0;
        it0++;
      }
      if (ans < maxs) ans = maxs;
      v.clear();
      v0.clear();
    }
  }
  cout << ans << endl;
  return 0;
}
