#include <bits/stdc++.h>
using namespace std;
int in[250];
int out[250];
int main() {
  int n, k, b = 0, ans = -10000;
  scanf("%d %d", &n, &k);
  vector<int> v(n);
  for (int i = 0; i < int(n); i++) scanf("%d", &v[i]), ans = max(ans, v[i]);
  for (int i = 0; i < int(n); i++) {
    for (int j = int(i); j <= int(n - 1); j++) {
      int ii = 0, io = 0, ki = 0;
      for (int I = 0; I < int(i); I++) out[io++] = v[I];
      for (int I = int(i); I <= int(j); I++) in[ii++] = v[I];
      for (int I = int(j + 1); I <= int(n - 1); I++) out[io++] = v[I];
      sort(in, in + ii);
      sort(out, out + io);
      reverse(out, out + io);
      int sum = 0;
      for (int I = int(i); I <= int(j); I++) sum += in[ki++];
      for (int I = 0; I < int(min(k, min(ii, io))); I++) {
        if (out[I] > in[I]) {
          sum -= in[I];
          sum += out[I];
        }
      }
      ans = max(ans, sum);
    }
  }
  printf("%d\n", ans);
  return 0;
}
