#include <bits/stdc++.h>
using namespace std;
const int MAXN = 500;
int a[MAXN];
vector<int> tmp1;
vector<int> tmp2;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  memset(a, 0, sizeof(a));
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  int ans = -1000;
  for (int i = 1; i <= n; i++) ans = max(ans, a[i]);
  for (int i = 1; i < n; i++)
    for (int j = i + 1; j <= n; j++) {
      int flg = 0;
      tmp1.clear();
      tmp2.clear();
      for (int k = i; k <= j; k++) {
        flg += a[k];
        tmp1.push_back(a[k]);
      }
      for (int k = 1; k < i; k++) tmp2.push_back(a[k]);
      for (int k = j + 1; k <= n; k++) tmp2.push_back(a[k]);
      sort(tmp1.begin(), tmp1.end());
      sort(tmp2.begin(), tmp2.end());
      int ss = tmp2.size();
      reverse(tmp2.begin(), tmp2.end());
      ss = min(j - i + 1, n - j + i - 1);
      for (int k = 0; k < min(m, ss); k++)
        if (tmp1[k] < tmp2[k]) {
          flg += tmp2[k];
          flg -= tmp1[k];
          ans = max(ans, flg);
        }
      ans = max(ans, flg);
    }
  printf("%d\n", ans);
}
