#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[200], ans = -(0x3f3f3f3f);
  cin >> n >> m;
  for (int i = 0; i < n; ++i) cin >> a[i];
  for (int i = 0; i < n; ++i) {
    for (int j = i; j < n; ++j) {
      vector<int> u, v;
      for (int k = 0; k < n; ++k) {
        if (k < i || k > j)
          u.push_back(a[k]);
        else
          v.push_back(a[k]);
      }
      sort(u.rbegin(), u.rend());
      for (int k = 0; k < m && k < u.size(); ++k) {
        v.push_back(u[k]);
      }
      sort(v.rbegin(), v.rend());
      int s = 0;
      for (int k = 0; k <= j - i; ++k) s += v[k];
      ans = max(ans, s);
    }
  }
  cout << ans;
}
