#include <bits/stdc++.h>
using namespace std;
void go() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) cin >> a[i];
  vector<int> b = a;
  sort(b.begin(), b.end());
  map<int, int> ma;
  for (int i = 0; i < n; ++i) ma[a[i]]++;
  int ans = -1e9;
  for (int l = 0; l < n; ++l) {
    for (int r = l; r < n; ++r) {
      vector<int> sub(r - l + 1);
      int s = 0, cnt = 0, p = n - 1;
      for (int i = 0; i < r - l + 1; ++i) {
        sub[i] = a[i + l];
        ma[sub[i]]--;
        s += sub[i];
      }
      sort(sub.begin(), sub.end());
      for (int i = 0; i < r - l + 1; ++i) {
        while (p > 0) {
          if (ma[b[p]] > 0)
            break;
          else
            p--;
        }
        if (b[p] <= sub[i]) break;
        if (ma[b[p]] > 0 && b[p] > sub[i]) {
          ma[sub[i]]++;
          ma[b[p]]--;
          s = s - sub[i] + b[p];
          sub[i] = b[p];
          cnt++;
        }
        if (cnt == k) break;
      }
      for (int i = 0; i < r - l + 1; ++i) ma[sub[i]]++;
      ans = max(ans, s);
    }
  }
  cout << ans << "\n";
}
int main() {
  int T = 1;
  while (T--) go();
  return 0;
}
