#include <bits/stdc++.h>
using namespace std;
#pragma(comment, linker("\STACK:50000000"))
int main() {
  ios_base::sync_with_stdio(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int ans = -1000;
  for (int l = 0; l < n; ++l) {
    for (int r = l; r < n; ++r) {
      vector<int> b, c;
      for (int i = 0; i < l; ++i) {
        c.push_back(a[i]);
      }
      for (int i = l; i <= r; ++i) {
        b.push_back(a[i]);
      }
      for (int i = r + 1; i < n; ++i) {
        c.push_back(a[i]);
      }
      sort((b).begin(), (b).end());
      sort((c).begin(), (c).end());
      reverse((c).begin(), (c).end());
      for (int i = 0;
           i < min({k, (int)(b).size(), (int)(c).size()}) && b[i] < c[i]; ++i) {
        swap(b[i], c[i]);
      }
      int s = 0;
      for (int i = 0; i < (int)(b).size(); ++i) {
        s += b[i];
      }
      ans = max(ans, s);
    }
  }
  cout << ans;
  return 0;
}
