#include <bits/stdc++.h>
using namespace std;
const int N = 2000;
const int INF = 1e9 + 7;
int n, k, ans;
int a[N], s[N];
bool vis[N];
vector<pair<int, int> > b;
int f(int l, int r) {
  int res = s[r] - s[l - 1], cnt = 0;
  memset(vis, false, sizeof vis);
  for (int i = 0; i < n; i++) {
    if (cnt == k) break;
    if (l > b[i].second || b[i].second > r) continue;
    for (int j = n - 1; j >= 0; j--)
      if (!vis[j] && (l > b[j].second || b[j].second > r) &&
          b[j].first > b[i].first) {
        cnt++;
        res += b[j].first - b[i].first;
        vis[j] = true;
        break;
      }
  }
  return res;
}
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
    b.push_back(pair<int, int>(a[i], i));
  }
  sort(b.begin(), b.end());
  ans = -INF;
  for (int l = 1; l <= n; l++) {
    for (int r = l; r <= n; r++) {
      ans = max(f(l, r), ans);
    }
  }
  cout << ans;
}
