#include <bits/stdc++.h>
using namespace std;
int n,k,a[200005],counter,counter2,maxi=-100001;
bool jedan,dva;
int main(){
    cin >> n >> k;
    for(int i=0; i<n; i++){
        cin >> a[i];
    }
    for(int i=0; i<k-1; i++){
        counter=0;
        counter2=0;
        jedan=false;
        dva=false;
        if(i!=0){
        for(int j=0; jedan==dva==true; j++){
            if(a[counter]==100001)counter++;
            else jedan=true;
            if(a[n-counter2]==100001)counter2++;
            else dva=true;
        }
        }
        if(a[counter]<0 && a[counter2]>=0){
            a[counter2]-=a[counter];
            a[counter]=100001;
        }
        else if(a[counter2]<0 && a[counter]>=0){
            a[counter]-=a[counter2];
            a[counter2]=100001;
        }
        else if(a[counter2]<0 && a[counter]<0){
            if(abs(a[counter])>=abs(a[counter2])){
            a[counter2]-=a[counter];
            a[counter]=100001;
            }
            else{
            a[counter]-=a[counter2];
            a[counter2]=100001;
            }
        }
        else{
            if(a[counter]>=a[counter2]){
            a[counter]-=a[counter2];
            a[counter2]=100001;
            }
            else{
            a[counter2]-=a[counter];
            a[counter]=100001;
            }
        }
    }
    for(int i=0; i<n; i++){
        if(a[i]!=100001 && a[i]>maxi)maxi=a[i];
    }
    cout << maxi << endl;
    return 0;
}