#include <bits/stdc++.h>
using namespace std;
vector<pair<int, int> > ar;
pair<int, int> r;
int a, n, k, sum[222], ans, vct, ect, h, iv, ie;
vector<int> v, e;
int main() {
  ar.push_back(make_pair(-1111, 0));
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a);
    ar.push_back(make_pair(a, i));
    sum[i] = sum[i - 1] + a;
  }
  sort(ar.begin(), ar.end());
  ans = 1 << 29;
  ans = -ans;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= i; j++) {
      vct = ect = 0;
      v.clear();
      e.clear();
      for (int y = 1; y <= n; y++) {
        r = ar[y];
        if (r.second >= j && r.second <= i) {
          if (vct < k) {
            v.push_back(r.first);
            vct++;
          } else
            break;
        }
      }
      for (int y = n; y >= 1; y--) {
        r = ar[y];
        if (r.second >= j && r.second <= i) {
          ;
        } else {
          if (ect < k) {
            e.push_back(r.first);
            ect++;
          } else
            break;
        }
      }
      h = sum[i] - sum[j - 1];
      int qw = h;
      iv = 0;
      ie = 0;
      while (1) {
        if (iv >= vct) break;
        if (ie >= ect) break;
        if (v[iv] > e[ie]) break;
        h += e[ie];
        h -= v[iv];
        iv++;
        ie++;
      }
      ans = max(ans, h);
    }
  }
  cout << ans << endl;
  return 0;
}
