#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector<int> a(n + 1);
  vector<vector<int> > inc(n + 1);
  vector<vector<int> > dec(n + 2);
  for (int i = 0; i < n; i++) {
    cin >> a[i + 1];
  }
  for (int i = 0; i <= n; i++) {
    if (i == 0)
      ;
    else {
      inc[i] = inc[i - 1];
      inc[i].push_back(a[i]);
      sort(inc[i].begin(), inc[i].end());
    }
  }
  for (int i = n; i >= 1; i--) {
    if (i == n)
      dec[i].push_back(a[i]);
    else {
      dec[i] = dec[i + 1];
      dec[i].push_back(a[i]);
      sort(dec[i].begin(), dec[i].end());
    }
  }
  int fsum = accumulate(a.begin(), a.end(), 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      vector<int> tmp(j - i + 1);
      copy(a.begin() + i, a.begin() + j + 1, tmp.begin());
      sort(tmp.begin(), tmp.end(), greater<int>());
      vector<int> incb = inc[i - 1];
      vector<int> deca = dec[j + 1];
      int swaps = 0, tmpsum = 0;
      while (swaps < k && tmp.size()) {
        int src = 0;
        int v1 = INT_MIN, v2 = INT_MIN, finval = INT_MIN;
        if (incb.size()) v1 = incb.back();
        if (deca.size()) v2 = deca.back();
        if (v1 == INT_MIN && v2 == INT_MIN) break;
        if (v1 >= v2) {
          src = 1;
          finval = v1;
        } else if (v1 < v2) {
          src = 2;
          finval = v2;
        }
        swaps++;
        if (finval > tmp.back()) {
          tmpsum += finval;
          if (src == 1)
            incb.pop_back();
          else if (src == 2)
            deca.pop_back();
          tmp.pop_back();
        } else
          break;
      }
      fsum = max(fsum, tmpsum + accumulate(tmp.begin(), tmp.end(), 0));
    }
  }
  cout << fsum;
  return 0;
}
