#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define F first
#define S second
#define pb push_back
#define pf push_front

namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

ll M = 1000000007;
typedef pair<int, int> P;

int main()
{
    int n, k;
    cin >> n >> k;
    deque<int> d;
    int ans = 0;
    rep(i, n)
    {
        int e;
        cin >> e;
        d.push_back(e);
    }
    int r = min(n, k);
    vector<bool> use(n, false);
    rep(i, r + 1)
    {

        if (i != 0)
            use[i - 1] = true;
        FOR(j, i + 1, n+1)
        {
            use[j - 1] = false;
        }
        rep(j, r + 1)
        {
            if (j != 0&&i+j<=k)
            {
                int ite = n - j ;
                if (i + j  <= k && ite > i)
                {
                    use[ite]=true;
                    int cnt = i + j;
                    priority_queue<int, vector<int>, greater<int>> tmp;
                    rep(l, n)
                    {
                        if (use[l])
                        {
                            tmp.push(d[l]);
                        }
                    }
                    int tans = 0;
                    int len = tmp.size();
                    //cout << "k-cnt " << k - cnt << endl;
                    //cout << "size " << tmp.size() << endl;
                    rep(l, k - cnt)
                    {
                       // cout << "top " << tmp.top() << endl;
                        if (tmp.top() < 0)
                        {
                            tmp.pop();
                            len--;
                        }
                    }
                    tans=0;

                    rep(l, len)
                    {
                        tans += tmp.top();
                        tmp.pop();
                    }
                  //  cout << "t " << tans << endl
                      //   << endl;
                    ans = max(tans, ans);
                }
            }
            else if (i + j <= k)
            {
                priority_queue<int, vector<int>, greater<int>> tmp;
                rep(l, n)
                {
                    if (use[l])
                    {
                        tmp.push(d[l]);
                    }
                }
                int tans = 0;
                //cout << "k-i " << k - i << endl;
                //cout << "size " << tmp.size() << endl;
                int len = tmp.size();
                rep(l, min(k - i, (int)len))
                {
                  //  cout << "top " << tmp.top() << endl;
                    if (tmp.top() < 0)
                    {
                        len--;
                        tmp.pop();
                    }
                }
                rep(l, len)
                {
                    tans += tmp.top();
                    tmp.pop();
                }
              //  cout << "t " << tans << endl
                //ab     << endl;
                ans = max(ans, tans);
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256