#include <bits/stdc++.h>
using namespace std;
long long p[10000];
vector<pair<long long, long long> > t;
int main() {
  long long n, k;
  cin >> n >> k;
  long long ans = -10000;
  for (long long i = 0; i < n; i++) {
    cin >> p[i];
    ans = max(ans, p[i]);
    t.push_back(make_pair(p[i], i));
  }
  sort(t.begin(), t.end());
  for (long long l = 0; l < n; l++) {
    for (long long r = l; r < n; r++) {
      vector<long long> temp;
      for (long long i = l; i <= r; i++) {
        temp.push_back(p[i]);
      }
      long long tk = 0;
      sort(temp.begin(), temp.end());
      vector<long long> fin;
      for (long long j = 0, i = t.size() - 1; j < temp.size() && i >= 0; i--) {
        if (t[i].second >= l && t[i].second <= r) {
          continue;
        } else {
          if (temp[j] < t[i].first) {
            temp[j] = t[i].first;
            tk++;
            j++;
          } else if (temp[j] > t[i].first) {
            break;
          }
        }
        if (tk == k) {
          break;
        }
      }
      long long s = 0;
      for (long long j = 0; j < temp.size(); j++) {
        s += temp[j];
      }
      ans = max(ans, s);
    }
  }
  cout << ans << "\n";
  return 0;
}
