#include <bits/stdc++.h>
using namespace std;
struct edje {
  int from, to;
  long long w;
  edje(int from, int to, long long w) : from(from), to(to), w(w) {}
  bool operator<(const edje& e) const { return w < e.w; }
};
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
const long long oo = (long long)((1e18) + 1);
const double eps = 1e-9;
const long long mod7 = 1000000007;
long long mod(long long a, long long b) { return (a % b + b) % b; }
long long strTonumModa(string s, long long athemod) {
  long long ans = 0;
  for (long long i = 0; i < ((long long)s.size()); i++) {
    ans = (ans * 10 + s[i] - '0') % athemod;
  }
  return ans;
}
long long mod_exp(long long base, long long p, long long MOD) {
  if (p == 0) return 1;
  if (p == 1) return base;
  long long ret = mod_exp(base, p / 2, MOD) % MOD;
  ret = (ret * ret) % MOD;
  if (p % 2 == 1) ret = (ret * base) % MOD;
  return ret;
}
string getstr(long long x) {
  stringstream ss;
  ss << x;
  string str = ss.str();
  return str;
}
bool comp(pair<long long, pair<long long, long long> > a,
          pair<long long, pair<long long, long long> > b) {
  return a.first > b.first;
}
int dr[] = {1, 1, 0, -1, -1, -1, 0, 1};
int dc[] = {0, 1, 1, 1, 0, -1, -1, -1};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, K;
  cin >> n >> K;
  int a[n];
  for (int i = 0; i < (int)(n); ++i) cin >> a[i];
  long long ans = -1 * 300000;
  for (int i = 0; i < (int)(n); ++i) {
    for (int j = (i); j < (int)(n); ++j) {
      long long curSum = 0;
      vector<int> candidateInterval, outInterval;
      for (int k = (i); k < (int)(j + 1); ++k) {
        candidateInterval.push_back(a[k]);
        curSum += a[k];
      }
      sort(candidateInterval.begin(), candidateInterval.end());
      for (int k = (0); k < (int)(i); ++k) outInterval.push_back(a[k]);
      for (int k = (j + 1); k < (int)(n); ++k) outInterval.push_back(a[k]);
      sort(outInterval.begin(), outInterval.end(), greater<int>());
      int l = 0, r = 0;
      int taken = K;
      while ((taken > 0) && (l < (int)((long long)candidateInterval.size())) &&
             (r < (int)((long long)outInterval.size()))) {
        if (candidateInterval[l] < outInterval[r]) {
          curSum -= candidateInterval[l];
          curSum += outInterval[r];
          l++;
          r++;
          taken--;
        } else if (candidateInterval[l] > outInterval[r]) {
          r++;
        } else {
          r++;
        }
      }
      ans = ans < curSum ? curSum : ans;
    }
  }
  cout << ans << endl;
  return 0;
}
