#include <iostream>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>

using namespace std;

using ll = long long;

const int MN = 102;

int n,k;
ll v[MN];

ll memo[MN][MN][MN];
bool memod[MN][MN][MN];
ll f(int ki, int l, int r){
	if(l>r)return 0;
	if(ki>=k)return 0;
	if(memod[ki][l][r])return memo[ki][l][r];
	memod[ki][l][r]=1;
	ll a = f(ki+1,l+1,r)+v[l];
	if(ki+1<k)a=max(a,f(ki+2,l+1,r));
	ll b = f(ki+1,l,r-1)+v[r];
	if(ki+1<k)b=max(b,f(ki+2,l,r-1));
	return memo[ki][l][r]=max(0ll,max(a,b));
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin>>n>>k;
	for(int i=0; i<n; ++i)cin>>v[i];
	cout<<f(0,0,n-1)<<endl;
	return 0;
}
