#include <bits/stdc++.h>
using namespace std;
int getint() {
  unsigned int c;
  int x = 0;
  while (((c = getchar()) - '0') >= 10) {
    if (c == '-') return -getint();
    if (!~c) exit(0);
  }
  do {
    x = (x << 3) + (x << 1) + (c - '0');
  } while (((c = getchar()) - '0') < 10);
  return x;
}
int n, k;
int in[222];
int main() {
  int i, j, tcc, tc = 1 << 28;
  for (tcc = 0; tcc < tc; tcc++) {
    n = getint(), k = getint();
    for (i = 0; i < n; i++) in[i] = getint();
    int s, t;
    int res = in[0];
    for (s = 0; s < n; s++)
      for (t = s; t < n; t++) {
        int sum = 0;
        vector<int> with;
        for (i = s; i <= t; i++) sum += in[i], with.push_back(in[i]);
        vector<int> other;
        for (i = 0; i < s; i++) other.push_back(in[i]);
        for (i = t + 1; i < n; i++) other.push_back(in[i]);
        sort(other.begin(), other.end(), greater<int>());
        sort(with.begin(), with.end());
        res = max(res, sum);
        int lm = min(other.size(), with.size());
        lm = min(lm, k);
        for (i = 0; i < lm; i++) {
          sum += other[i];
          sum -= with[i];
          res = max(res, sum);
        }
      }
    cout << res << endl;
  }
  return 0;
}
