#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, p;
  scanf("%d%d", &n, &p);
  int a[n], maxi = -3000000;
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      vector<int> in, out;
      for (int k = 0; k < n; k++) {
        if (k >= i && k <= j)
          in.push_back(a[k]);
        else
          out.push_back(a[k]);
      }
      sort(in.begin(), in.end());
      sort(out.rbegin(), out.rend());
      int sum = 0;
      for (int k = 0; k < in.size(); k++) sum += in[k];
      int ptr = 0, inptr = 0, outptr = 0;
      while (ptr < p && inptr < in.size() && outptr < out.size() &&
             in[inptr] < out[outptr]) {
        sum += out[outptr] - in[inptr];
        ptr++;
        inptr++;
        outptr++;
      }
      maxi = max(maxi, sum);
    }
  }
  cout << maxi << endl;
}
