#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
int a[222];
vector<int> kiss;
vector<int> miss;
int main() {
  int n, m, ans, i, j, k;
  while (cin >> n >> m) {
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    ans = -inf;
    for (i = 1; i <= n; i++) {
      int sum = 0;
      for (j = i; j <= n; j++) {
        kiss.clear();
        miss.clear();
        sum = 0;
        for (k = i; k <= j; k++) {
          kiss.push_back(a[k]);
          sum += a[k];
        }
        for (k = 1; k <= n; k++) {
          if (k < i || k > j) miss.push_back(a[k]);
        }
        sort(kiss.begin(), kiss.end());
        sort(miss.begin(), miss.end());
        ans = max(ans, sum);
        for (k = 1; k <= m && k <= kiss.size() && k <= miss.size(); k++) {
          sum -= kiss[k - 1];
          sum += miss[miss.size() - k];
          ans = max(ans, sum);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
