#include <bits/stdc++.h>
using namespace std;
template <class T>
bool INRANGE(T x, T a, T b) {
  return a <= x && x <= b;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
void printvec(vector<T> v) {
  for (T t : v) cout << t << " ";
  cout << endl;
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  vector<long long> v(N);
  for (int i = 0; i < (N); ++i) cin >> v[i];
  long long ans = 0;
  for (int l = 0; l < (K); ++l)
    for (int r = 0; r < (K - l); ++r) {
      if (l + r > N) continue;
      int d = K - l - r;
      long long score = 0;
      vector<int> s;
      for (int i = 0; i < (l); ++i) {
        score += v[i];
        s.emplace_back(v[i]);
      }
      for (int i = (N - r); i < (N); ++i) {
        score += v[i];
        s.emplace_back(v[i]);
      }
      sort((s).begin(), (s).end());
      for (int i = 0; i < (d); ++i) {
        if (i >= s.size()) break;
        if (s[i] > 0) break;
        score -= s[i];
      }
      ans = max(ans, score);
    }
  cout << ans << endl;
  return 0;
}
