#include <bits/stdc++.h>
using namespace std;

#define int long long
//struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (LL i = (a); i < (LL)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define DEPS(i, a, n) for (LL i = (a); i >= (LL)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i = (n).begin(); i != (n).end(); ++i)
#define REACH(i, n) for (auto&& i = (n).rbegin(); i != (n).rend(); ++i)
#define FILL(array,value) fill((array), (array) + sizeof(array)/sizeof((array)[0]), (value))

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using LL = long long;
using ULL = unsigned long long;
using D = double;
using P = complex<D>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VS = vector<string>;
using PII = pair<int, int>;
using PIS = pair<int, string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const LL LINF = 1001001001001001001LL;
const int MOD = 1e9 + 7;
const D EPS = 1e-12;
const D PI=3.1415926535897932384626;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline LL IN() {LL x; cin >> x; return x;}
inline VS split(const string& t, char c) {VS v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {REP(i, v.size()) cout << v[i] << (i != (LL)v.size() - 1 ? s : "\n");}

int N, K;
VI V;
signed main() {
  N=in();
  K=in();
  REP(i,N) V.pb(in());

  int v_max = 0;

  int minget = min(N,K); // 持ってこれる最大は，宝石数N個，もしくは制約のK個
  REP(getK, minget+1) { // 持ってこれるパターンを全探索

    int minput = min(getK, K-getK); // 置きに行く最大は，持ってきた宝石数，もしくは制約のK-getK個
    REP(putK, minput+1) { // 置きに行くパターンを全探索

      REP(left, getK+1) { // 左からleft個取れば，右からはright個取ることになる
        int right = getK - left;

        // 左右から持ってきて
        VI hand;
        REP(i,left) hand.push_back(V[i]);
        REP(i,right) hand.push_back(V[N-1-i]);
        // ソートして
        sort(ALL(hand));
        // 置きに行く個数だけ削除
        REP(i,putK) hand.erase(hand.begin());
        // 総和を計算
        int v_sum = accumulate(ALL(hand), 0LL);
        // 最大値更新
        chmax(v_max, v_sum);
      }
    }
  }
  print(v_max);
  return 0;
}

Measured memory_bytes: 256