#include <bits/stdc++.h>
using namespace std;
using ull = unsigned long long;
const int INF = (int)1e9;
const long long IINF = 1LL << 62;
const int maxn = 10000005;
long long modexpo(long long a, long long b) {
  long long res = 1LL;
  while (b > 0) {
    if (b & 1) res = (res * a) % 1000000007;
    a = (a * a) % 1000000007;
    b >>= 1;
  }
  return res;
}
vector<pair<int, int>> adj[100005];
long long dist[100005];
int n;
void dfs(int node, int par) {
  for (auto ch : adj[node]) {
    if (ch.first == par) continue;
    dist[ch.first] = dist[node] + ch.second;
    dfs(ch.first, node);
  }
}
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  long long res = 0;
  for (int i = -1; i <= n; i++) {
    for (int j = i + 1; j <= n; j++) {
      if (i + 1 + n - j > k) continue;
      int z = k - (i + 1 + n - j);
      long long sum = 0;
      vector<int> tmp;
      for (int k = 0; k <= i; k++) {
        sum += a[k];
        if (a[k] < 0) tmp.push_back(a[k]);
      }
      for (int k = j; k < n; k++) {
        sum += a[k];
        if (a[k] < 0) tmp.push_back(a[k]);
      }
      sort(tmp.rbegin(), tmp.rend());
      while (!tmp.empty() && z > 0) {
        sum += abs(tmp.back());
        tmp.pop_back();
        z--;
      }
      res = max(res, sum);
    }
  }
  cout << res;
}
