#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16777216")
using namespace std;
inline long FastMax(long x, long y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ y;
}
inline long FastMin(long x, long y) {
  return (((y - x) >> (32 - 1)) & (x ^ y)) ^ x;
}
long IR[] = {0, -1, 0, 1, -1, -1, 1, 1};
long IC[] = {1, 0, -1, 0, 1, -1, -1, 1};
long N, K;
long A[1007 + 7];
int main(void) {
  long i, j, Icase, k = 0;
  cin >> N >> K;
  for (i = 1; i <= N; i++) {
    cin >> A[i];
  }
  long ans = -1000000007;
  for (i = 1; i <= N; i++) {
    for (j = i; j <= N; j++) {
      vector<long> vc1, vc2;
      long s = 0;
      for (k = 1; k <= N; k++) {
        if (k >= i and k <= j) {
          vc1.push_back(A[k]);
          s += A[k];
        } else {
          vc2.push_back(A[k]);
        }
      }
      ans = max(ans, s);
      sort(vc1.begin(), vc1.end());
      reverse(vc1.begin(), vc1.end());
      sort(vc2.begin(), vc2.end());
      for (k = 1; k <= K; k++) {
        if (!vc1.size() or !vc2.size()) break;
        s -= vc1[vc1.size() - 1];
        s += vc2[vc2.size() - 1];
        vc1.pop_back();
        vc2.pop_back();
        ans = max(ans, s);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
