#include <bits/stdc++.h>
using namespace std;
template <class T>
void mx(T& a, const T& b) {
  if (a < b) a = b;
}
template <class T>
void mn(T& a, const T& b) {
  if (a > b) a = b;
}
int A[200];
int I[200];
int n, k;
inline int solve(int l, int r) {
  vector<int> a, b;
  copy(A + l, A + r, back_inserter(a));
  copy(A, A + l, back_inserter(b));
  copy(A + r, A + n, back_inserter(b));
  partial_sort(a.begin(), a.begin() + min(k, (int)a.size()), a.end());
  partial_sort(b.begin(), b.begin() + min(k, (int)b.size()), b.end(),
               greater<int>());
  int sum = 0;
  for (int i = l; i < r; ++i) sum += A[i];
  for (int i = 0; i < min(k, (int)min(a.size(), b.size())); ++i)
    if (a[i] < b[i]) {
      sum -= a[i];
      sum += b[i];
    }
  return sum;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> A[i];
  int ans = -10000;
  for (int r = 0; r <= n; ++r)
    for (int l = 0; l < r; ++l) mx(ans, solve(l, r));
  cout << ans << endl;
  return 0;
}
