#include <bits/stdc++.h>
using namespace std;
const int M = 205;
multiset<int> inside, outside;
multiset<int>::iterator in, out;
int A[M], n, m, ans = -200000;
inline int Max(int x, int y) {
  if (x > y) return x;
  return y;
}
inline int Min(int x, int y) {
  if (x < y) return x;
  return y;
}
void solve(int res) {
  int a = Min(inside.size(), outside.size());
  if (a > m) a = m;
  in = inside.begin();
  out = outside.begin();
  while (a > 0) {
    int c = *in;
    int d = -(*out);
    if (c >= d) break;
    res += d - c;
    in++;
    out++;
    a--;
  }
  ans = Max(res, ans);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++) {
    inside.clear();
    outside.clear();
    for (int j = 1; j <= n; j++) outside.insert(-A[j]);
    int res = 0;
    for (int j = i; j <= n; j++) {
      res += A[j];
      inside.insert(A[j]);
      outside.erase(outside.find(-A[j]));
      solve(res);
    }
  }
  printf("%d\n", ans);
  return 0;
}
