#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define fi first
#define sc second
#define th third
#define fo fourth
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ldb double
#define endl "\n"
int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    ll n,k;
    cin>>n>>k;
    ll a[n];
    for(int i=0;i<n;i++) cin>>a[i];
	for(int i=1;i<n-1;i++)
	{
		a[i]=abs(a[i]);
	}
    if(n==k)
    {
        ll sum=0;
        for(int i=0;i<n;i++) sum+=a[i];
        ll rez;
        if(a[0]>a[n-1]) rez=sum-2*a[n-1];
        else rez=sum-2*a[0];
        cout<<rez<<endl;
    }
    else
    {
        ll rez=-INT_MAX;
        for(int i=0;i<n;i++)
        {
            ll sum1=0,sum2=0,sol;
            if(i<k-1) sum1=0;
            else
            {
                vector<ll> v1;
                v1.clear();
                for(int j=0;j<i;j++) v1.pb(a[j]);
                sort(v1.begin(),v1.end(),greater<ll>());
                for(int j=0;j<k-1;j++) sum1+=v1[j];
            }
            if(i>n-(k-1)-1) sum2=0;
            else
            {
                vector<ll> v2;
                v2.clear();
                for(int j=i+1;j<n;j++) v2.pb(a[j]);
                sort(v2.begin(),v2.end(),greater<ll>());
                for(int j=0;j<k-1;j++) sum2+=v2[j];
            }
            sol=max(sum1,sum2)-a[i];
            rez=max(rez,sol);
        }
        cout<<rez<<endl;
    }
    return 0;
}