#include <bits/stdc++.h>
using namespace std;
int n, k, a[2007], neg, one, two, ans;
multiset<int> inside, outside;
int main() {
  ios::sync_with_stdio(0);
  cin >> n >> k;
  ans = -2000000;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      for (int t = i; t <= j; t++) {
        inside.insert(a[t]);
      }
      for (int t = 0; t < i; t++) {
        outside.insert(a[t]);
      }
      for (int t = j + 1; t < n; t++) {
        outside.insert(a[t]);
      }
      for (int t = 0; t < k; t++) {
        if (!inside.size() || !outside.size()) break;
        one = *inside.begin();
        two = *outside.rbegin();
        if (one < two) {
          inside.insert(two);
          outside.erase(outside.find(two));
          outside.insert(one);
          inside.erase(inside.find(one));
        }
      }
      int tot = 0;
      for (multiset<int>::iterator it = inside.begin(); it != inside.end();
           it++) {
        tot += *it;
      }
      ans = max(tot, ans);
      inside.clear();
      outside.clear();
    }
  }
  cout << ans;
}
