// {{{
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <complex>
#include <vector>
#include <list>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define FOR(i, a, b) for(ll i = static_cast<ll>(a); i < static_cast<ll>(b); i++)
#define FORR(i, a, b) for(ll i = static_cast<ll>(a); i >= static_cast<ll>(b); i--)
#define REP(i, n) for(ll i = 0ll; i < static_cast<ll>(n); i++)
#define REPR(i, n) for(ll i = static_cast<ll>(n); i >= 0ll; i--)
#define ALL(x) (x).begin(), (x).end()

#define DBG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl;

using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using IP = pair<int, P>;
using LLP = pair<ll, LP>;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};

constexpr int INF = 100000000;
constexpr ll LINF = 10000000000000000ll;
constexpr int MOD = static_cast<int>(1e9 + 7);
constexpr double EPS = 1e-9;

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    size_t sz = v.size();
    os << "[";
    for (size_t i = 0; i < sz-1; i++) {
        os << v[i] << ", ";
    }
    os << v[sz-1] <<  "]";
    return os;
}

template<typename T>
void printArray(T *arr, size_t sz) {
    cerr << "[";
    for (size_t i = 0; i < sz-1; i++) {
        cerr << arr[i] << ",";
    }
    cerr << arr[sz-1] <<  "]";
}

static inline ll mod(ll x, ll m)
{
    ll y = x % m;
    return (y >= 0 ? y : y+m);
}


// print floating-point number
// cout << fixed << setprecision(12) <<

// }}}

int N, K;
ll v[51];

#if 0
bool isOk(ull b)
{
    vector<bool> left(N), right(N);
    left[N-1] = (b>>(N-1))&1;
    right[0] = (b>>0)&1;
    REPR (i, N-2) {
        if (((b>>i)&1) && left[i+1]) left[i] = true;
    }
    FOR (i, 1, N) {
        if (((b>>i)&1) && right[i-1]) right[i] = true;
    }
    FOR (i, 1, N-1) {
        if (((b>>i)&1) && !left[i] && !right[i])
            return false;
    }
    return true;
}
#endif

void solve()
{
    ll ans = 0;
    ull b = 0;
    REP (i, N+1) {
        REP (j, i+1) {
            ull b = ((((1ull<<j)-1) << (N-j)) | (1ull<<(i-j))-1);
            //cout << i << " " << j << " " << bitset<50>(b) << endl;
            //if (isOk(b)) {
                //cout << bitset<50>(b) << endl;
                int pc = __builtin_popcountll(b);
                if (pc <= K) {
                    priority_queue<ll, vector<ll>, greater<ll> > q;
                    REP (i, N) {
                        if ((b>>i)&1) {
                            q.push(v[i]);
                        }
                    }
                    ll a = 0;
                    while (!q.empty()) {
                        ll x = q.top();
                        if (x < 0 && pc < K) {
                            pc++;
                        } else {
                            a += x;
                        }
                        q.pop();
                    }
                    //cout << bitset<50>(b) << " " << a << endl;
                    ans = max(ans, a);
                }
            //}
        }
    }
    cout << ans << endl;
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    REP (i, N) cin >> v[i];
    solve();
    return 0;
}

// vim:set foldmethod=marker:


Measured memory_bytes: 256