#include <bits/stdc++.h>
using namespace std;
const int mmax = 1e2 + 5;
int a[mmax], l, r;
int an[mmax], top, antmp[mmax];
long long maxans, ans;
bool bo[mmax][mmax][mmax];
void dfs(int k) {
  if (bo[k][l][r]) return;
  bo[k][l][r] = 1;
  int ji = 0;
  for (int i = 0; i < top; i++) antmp[i] = an[i];
  sort(antmp, antmp + top);
  for (int i = 0; i < k && i < top; i++)
    if (antmp[i] < 0)
      ji += antmp[i];
    else
      break;
  maxans = max(maxans, max(ans, ans - ji));
  if (k == 0) return;
  if (k >= 0 && r >= l) {
    {
      ans += a[l];
      an[top++] = a[l];
      l++;
      dfs(k - 1);
      top--;
      l--;
      ans -= a[l];
    }
    {
      ans += a[r];
      an[top++] = a[r--];
      dfs(k - 1);
      top--;
      r++;
      ans -= a[r];
    }
  }
}
int main() {
  ans = 0;
  maxans = 0;
  int n, m;
  cin >> n >> m;
  l = 1, r = n, top = 0;
  for (int i = 1; i <= n; i++) cin >> a[i];
  dfs(m);
  cout << maxans << endl;
}
