#include <bits/stdc++.h>
using namespace std;
int a[250];
multiset<int, greater<int> > Swap;
multiset<int> E;
int main() {
  int n, p;
  scanf("%d %d", &n, &p);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  int tr, tl;
  int maxi = -1000000000;
  for (int l = 0; l < n; l++) {
    for (int r = l; r < n; r++) {
      Swap.clear();
      E.clear();
      int sum = 0;
      for (int k = l; k <= r; k++) sum += a[k];
      for (int k = l; k <= r; k++) E.insert(a[k]);
      for (int k = 0; k < l; k++) Swap.insert(a[k]);
      for (int k = r + 1; k < n; k++) Swap.insert(a[k]);
      set<int>::iterator its = E.begin();
      set<int, greater<int> >::iterator itb = Swap.begin();
      int k = 0;
      while (k < p && itb != Swap.end() && its != E.end()) {
        if (*itb > *its) {
          sum += *itb;
          sum -= *its;
        }
        k++;
        itb++;
        its++;
      }
      maxi = max(maxi, sum);
    }
  }
  printf("%d\n", maxi);
}
