#include <bits/stdc++.h>
using namespace std;
long long Resi(vector <long long> &a,int n,int k){
if(n!=k){
long long rez=0;
for(int i=0;i<n-1;i++){
vector <long long> b;
vector <long long> c;
for(int j=0;j<=i;j++){c.push_back(-a[j]);}
for(int j=i+1;j<n;j++)b.push_back(a[j]);
sort(c.begin(),c.end());
reverse(c.begin(),c.end());
sort(b.begin(),b.end());
reverse(b.begin(),b.end());
vector <long long> d;
for(int i=0;i<k-1;i++){
    d.push_back(b[i]);
    d.push_back(c[i]);
}
sort(d.begin(),d.end());
reverse(d.begin(),d.end());
long long curr=0;
for(int j=0;j<k;j++){
    curr+=d[j];
}
rez=max(curr,rez);
}


return rez;
}

long long S=0;
for(int i=0;i<n;i++)S+=a[i];
long long rez=0;
for(int i=0;i<n-1;i++){
        S-=2*a[i];
rez=max(rez,S);
}
return rez;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
int n,k;
cin >>n>>k;

vector <long long> a(n);
for(int i=0;i<n;i++){
    cin >>a[i];
}

vector<long long> b=a;
reverse(b.begin(),b.end());
long long rez=max(Resi(a,n,k),Resi(b,n,k));
cout <<rez<<endl;
}