#include <bits/stdc++.h>
using namespace std;
inline int ReadInt() {
  char c;
  while (c = getchar(), c < '0' || c > '9')
    ;
  int x = c - '0';
  while (c = getchar(), c >= '0' && c <= '9') x = x * 10 + c - '0';
  return x;
}
const int N = 2e2 + 1;
int n, a[N], k;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> a[i];
  int ans = -(int)1e9, cur, cur1, cur2;
  vector<int> v1, v2;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      v1.clear();
      v2.clear();
      cur = 0;
      for (int i1 = i; i1 <= j; i1++) {
        cur += a[i1];
        v1.push_back(a[i1]);
      }
      for (int i1 = 1; i1 < i; i1++) v2.push_back(a[i1]);
      for (int i1 = j + 1; i1 <= n; i1++) v2.push_back(a[i1]);
      sort(v1.begin(), v1.end());
      sort(v2.begin(), v2.end());
      reverse(v2.begin(), v2.end());
      cur1 = cur2 = 0;
      ans = max(ans, cur);
      for (int i1 = 0; i1 < min(k, min((int)v1.size(), (int)v2.size())); i1++) {
        cur1 += v1[i1];
        cur2 += v2[i1];
        ans = max(ans, cur - cur1 + cur2);
      }
    }
  }
  cout << ans << '\n';
}
