#include <bits/stdc++.h>
using namespace std;
const int N = 4e5;
pair<int, int> p[N];
int a[N];
priority_queue<int> q1, q2;
int main() {
  int i, j, k, k1, n;
  while (scanf("%d%d", &n, &k1) != EOF) {
    for (i = 0; i < n; ++i) {
      scanf("%d", a + i);
    }
    int k2 = k1;
    int ans = -9999999;
    for (i = 0; i < n; ++i) {
      for (j = i; j < n; ++j) {
        int sum = 0;
        while (!q1.empty()) {
          q1.pop();
        }
        while (!q2.empty()) {
          q2.pop();
        }
        for (k = 0; k < n; ++k) {
          if (k < i || k > j) {
            q2.push(a[k]);
          } else {
            q1.push(-a[k]);
            sum += a[k];
          }
        }
        k1 = k2;
        while (k1-- && q1.size() > 0 && q2.size() > 0) {
          int x = -q1.top();
          int y = q2.top();
          q1.pop();
          q2.pop();
          if (x >= y) {
            break;
          }
          sum -= x;
          sum += y;
        }
        ans = max(ans, sum);
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
