#include <bits/stdc++.h>
using namespace std;
int cnt[205];
int n, m;
int has[205], other[205], hsize, osize, sum;
int main() {
  while (cin >> n >> m) {
    for (int i = 0; i < n; i++) {
      cin >> cnt[i];
    }
    int ans = -1005;
    for (int i = 0; i < n; i++) {
      for (int j = i; j < n; j++) {
        hsize = osize = sum = 0;
        for (int k = 0; k < n; k++) {
          if (k >= i && k <= j) {
            has[hsize++] = cnt[k];
            sum += cnt[k];
          } else {
            other[osize++] = cnt[k];
          }
        }
        sort(has, has + hsize);
        sort(other, other + osize);
        int fit = 0;
        for (int k = 0; k < min(m, hsize); k++) {
          if (osize - k - 1 >= 0 && other[osize - k - 1] - has[k] >= 0) {
            fit += other[osize - k - 1] - has[k];
          }
        }
        ans = max(ans, fit + sum);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
