#include <bits/stdc++.h>
using namespace std;
int a[222], dp[222];
vector<int> v, vv;
bool compare(int aa, int bb) { return aa > bb; }
int main() {
  int i, j, k, n, m, x, y;
  cin >> n >> m;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    dp[i] = a[i] + dp[i - 1];
  }
  int max = -999999999;
  for (i = 1; i <= n; i++) {
    for (j = i; j <= n; j++) {
      int temp_sum = dp[j] - dp[i - 1];
      for (k = 1; k <= n; k++) {
        if (k >= i && k <= j) {
          v.push_back(a[k]);
        } else
          vv.push_back(a[k]);
      }
      sort(v.begin(), v.end());
      sort(vv.begin(), vv.end(), compare);
      for (k = 0; k < m && k < vv.size() && k < v.size(); k++) {
        if (vv[k] > v[k]) {
          temp_sum = temp_sum - v[k] + vv[k];
        }
      }
      max = max > temp_sum ? max : temp_sum;
      v.clear();
      vv.clear();
    }
  }
  cout << max << endl;
  return 0;
}
