#include <bits/stdc++.h>
using namespace std;
const int maxN = 1005;
const int maxM = 15;
int n, k, ht;
int a[maxN], b[maxN];
bool ok[maxN];
void nhap() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) b[i] = i;
}
bool cmp(int x, int y) {
  if (x < ht) return false;
  if (y < ht) return true;
  return x < y;
}
int find_m(int l, int r) {
  int ans = 1000;
  for (int i = 0; i < n; i++)
    if (i < l || i > r)
      if (ok[i] && a[i] > a[ans]) ans = i;
  ok[ans] = false;
  return ans;
}
void xuly() {
  vector<int> my;
  my.clear();
  int ans = -1000000;
  a[1000] = ans;
  for (int i = 0; i < n; i++) ans = max(ans, a[i]);
  for (int i = 0; i < n; i++) {
    for (int len = 1; len < n; len++) {
      int j = i + len;
      int s = 0;
      my.clear();
      memset(ok, true, sizeof(ok));
      int left = k;
      for (int l = i; l < j + 1; l++) {
        my.push_back(a[l]);
        s += a[l];
      }
      ans = max(ans, s);
      do {
        if (left == 0) break;
        int vt = 0;
        for (int i = 0; i < my.size(); i++)
          if (my[i] < my[vt]) vt = i;
        int the = find_m(i, j);
        s += (a[the] - my[vt]);
        my.erase(my.begin() + vt);
        ans = max(ans, s);
        --left;
      } while (left > 0 && my.size() > 0);
    }
  }
  cout << ans;
}
int main() {
  nhap();
  xuly();
  return 0;
}
