#include <bits/stdc++.h>
using namespace std;
int n, K;
int a[143];
int ans = -0x3f3f3f3f;
int main(int argc, char const *argv[]) {
  scanf("%d%d", &n, &K);
  for (int i = 1; i <= n; ++i) {
    scanf("%d", &a[i]);
  }
  for (int i = 1; i <= min(K + 1, n); ++i) {
    for (int j = i + n - K - 1; j <= n; ++j) {
      vector<int> vec;
      for (int k = 1; k < i; ++k) {
        vec.push_back(a[k]);
      }
      for (int k = j + 1; k <= n; ++k) {
        vec.push_back(a[k]);
      }
      sort(vec.begin(), vec.end());
      int kk = K - (i - 1) - (n - j), pla = 0;
      while (kk > 0 && pla < vec.size() && vec[pla] <= 0) {
        --kk;
        ++pla;
      }
      int sum = 0;
      for (int k = pla; k < vec.size(); ++k) {
        sum += vec[k];
      }
      ans = max(ans, sum);
    }
  }
  printf("%d\n", ans);
  return 0;
}
