#include <bits/stdc++.h>
using namespace std;
int a[1005];
int main() {
  int cc;
  int n, m;
  while (cin >> n >> m) {
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = -0x3f3f3f3f;
    for (int i = 1; i <= n; i++)
      for (int j = i; j <= n; j++) {
        vector<int> ss, pp;
        int sum = 0;
        for (int k = i; k <= j; k++) {
          sum += a[k];
          ss.push_back(a[k]);
        }
        for (int k = 1; k < i; k++) pp.push_back(a[k]);
        for (int k = j + 1; k <= n; k++) pp.push_back(a[k]);
        sort(ss.begin(), ss.end());
        sort(pp.begin(), pp.end());
        int l = 0, r = pp.size() - 1, p = m;
        while ((p--) && l < ss.size() && r >= 0) {
          if (ss[l] < pp[r]) {
            sum -= ss[l];
            sum += pp[r];
            l++;
            r--;
          }
        }
        ans = max(ans, sum);
      }
    cout << ans << endl;
  }
  return 0;
}
