#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  int i, a[n];
  for (i = 0; i < n; ++i) cin >> a[i];
  int j, l, ans = a[0];
  for (i = 0; i < n; ++i) {
    for (j = i; j < n; ++j) {
      vector<int> big, small;
      for (l = 0; l < n; ++l) {
        if (l >= i && l <= j)
          big.push_back(a[l]);
        else
          small.push_back(a[l]);
      }
      sort(big.begin(), big.end());
      sort(small.rbegin(), small.rend());
      int sum = 0;
      for (l = 0; l < big.size(); ++l) {
        sum += big[l];
      }
      for (int e = 0; e <= k && e <= big.size() && e <= small.size(); ++e) {
        int tmp = sum;
        for (l = 0; l < e; ++l) {
          tmp -= big[l];
          tmp += small[l];
        }
        ans = max(ans, tmp);
      }
    }
  }
  cout << ans;
  return 0;
}
