#include <bits/stdc++.h>
#define ll long long
#define MAXN 200010
using namespace std;
ll n,k,a[MAXN];
vector<string> v,r;
vector<ll> br;
void Napici(string t,ll br1)
{
    if (t.size()==n)
    {
        if (br1==k)
            v.push_back(t);
        return;
    }
    Napici(t+'0',br1);
    Napici(t+'1',br1+1);
}
void Raspored(string t)
{
    if (t.size()==k-1)
    {
        r.push_back(t);
        return;
    }
    Raspored(t+'0');
    Raspored(t+'1');
}
ll Provera(string s)
{
    ll l=0,d=k-1,p;
    vector<ll> br1=br;
    for (ll i=0;i<k-1;i++)
    {
        if (s[i]=='0')
        {
            br1[d]-=br1[l];
            l++;
            p=br1[d];
            continue;
        }
        br1[l]-=br1[d];
        d--;
        p=br1[l];
    }
    return p;
}
int main()
{
    ///ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> k;
    for (ll i=0;i<n;i++)
        cin >> a[i];
    if (n<=10)
    {
        ll res=LLONG_MIN;
        Napici("",0);
        Raspored("");
        for (ll i=0;i<v.size();i++)
        {
            string s=v[i];
            br.clear();
            for (ll j=0;j<n;j++)
            {
                if (s[j]=='1')
                    br.push_back(a[j]);
            }
            for (ll j=0;j<r.size();j++)
                res=max(res,Provera(r[j]));
        }
        cout << res << "\n";
    }
    return 0;
}