#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string.h>
#include<vector>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
typedef long long ll;
int a[35],maxn,n;
bool flag[35];
void dfs(int id,int left,int sum){
if(n-id+2<left*2)return ;//剪枝,the rest of tree holes is not enough
if(left==0){//find a successful way
maxn=max(maxn,sum);
return ;
}
if(id>n)return ;//a failed way
if(id==n){//to the final hole
if(left==1&&flag[1]==false&&flag[n-1]==false){
sum+=a[n];
maxn=max(maxn,sum);
}
return ;
}
flag[id]=true;
dfs(id+2,left-1,sum+a[id]);//select. Then goto id+2 not id+1
flag[id]=false;
dfs(id+1,left,sum);//not select
return ;
}
int main(){
int m;
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
}
if(m>n/2){
cout<<"Error!"<<endl;
return 0;
}
memset(flag,false,sizeof(flag));
maxn=-300000;
dfs(1,m,0);
cout<<maxn<<endl;
return 0;
}
// /\ | / |**、
// / \ | / | \
// / \ |/ | / _____ ____ | /
// /------\ |\ |__/ / \ \ /\ / / \ | /
// / \ | \ | / \ \ / \ / /______\ |/
// / \ | \ | \ / \ / \ / \ |
// / \ | \ | \_____/ \/ \/ \_____ |
/**
* ┏┓ ┏┓
* ┏┛┗━━━━━━━┛┗━━━┓
* ┃ ┃
* ┃ ━ ┃
* ┃ > < ┃
* ┃ ┃
* ┃... ⌒ ... ┃
* ┃ ┃
* ┗━┓ ┏━┛
* ┃ ┃ Code is far away from bug with the animal protecting
* ┃ ┃ 神兽保佑,代码无bug
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┃
* ┃ ┗━━━┓
* ┃ ┣┓
* ┃ ┏┛
* ┗┓┓┏━┳┓┏┛
* ┃┫┫ ┃┫┫
* ┗┻┛ ┗┻┛
*/
// warm heart, wagging tail,and a smile just for you!
//
// _ooOoo_
// o8888888o
// 88" . "88
// (| -_- |)
// O\ = /O
// ____/`---'\____
// .' \| |// `.
// / \||| : |||// \
// / _||||| -:- |||||- \
// | | \\ - /// | |
// | \_| ''\---/'' | |
// \ .-\__ `-` ___/-. /
// ___`. .' /--.--\ `. . __
// ."" '< `.___\_<|>_/___.' >'"".
// | | : `- \`.;`\ _ /`;.`/ - ` : | |
// \ \ `-. \_ __\ /__ _/ .-` / /
// ======`-.____`-.___\_____/___.-`____.-'======
// `=---='
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//