#include <bits/stdc++.h>
using namespace std;
int n, q, a[333], res = -10000000, rr;
vector<int> v1, v2;
int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      v1.clear();
      v2.clear();
      for (int k = 1; k <= n; k++) {
        if (k >= i && k <= j)
          v1.push_back(a[k]);
        else
          v2.push_back(a[k]);
      }
      sort(v1.begin(), v1.end());
      sort(v2.begin(), v2.end());
      rr = 0;
      for (int k = 0; k < v1.size(); k++) {
        if (k < q && k < v2.size())
          rr += max(v1[k], v2[v2.size() - 1 - k]);
        else
          rr += v1[k];
      }
      res = max(res, rr);
    }
  }
  cout << res << endl;
}
