#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
const int mod = 1e9 + 7;
const long long INF = 4e18 + 5;
int n, k;
int a[202];
int O[202], M[202];
int ans = -inf;
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; ++i) cin >> a[i];
  for (int l = 1; l <= n; ++l) {
    for (int r = l; r <= n; ++r) {
      int cur = 0;
      int cntm = 0, cnto = 0;
      for (int i = 1; i < l; ++i) O[++cnto] = a[i];
      for (int i = r + 1; i <= n; ++i) O[++cnto] = a[i];
      for (int i = l; i <= r; ++i) {
        M[++cntm] = a[i];
        cur += a[i];
      }
      sort(O + 1, O + cnto + 1);
      sort(M + 1, M + cntm + 1);
      for (int i = 1; i <= cnto; ++i) O[i] += O[i - 1];
      for (int i = 1; i <= cntm; ++i) M[i] += M[i - 1];
      int lim = min(min(cnto, cntm), k);
      for (int d = 0; d <= lim; ++d) {
        ans = max(ans, cur - M[d] + O[cnto] - O[cnto - d]);
      }
    }
  }
  cout << ans;
  return 0;
}
