#include <bits/stdc++.h>
using namespace std;

#pragma GCC optimize("O2")

//loops
#define FOR(n)              for(uint i=0;i<n;i++)
#define FORJ(n)             for(int j=0;j<n;j++)
#define FORN(n,x)           for(int x=0;i<n;i++)
#define REVERSE_FOR(n)      for(int i=n-1;i>=0;i--)
#define ODD_FOR(n)          for(int i=1;i<n;i+=2)
#define EVEN_FOR(n)         for(int i=0;i<n;i+=2)
#define FROM(n,m)           for(int i=n;i<m;i++)
#define FROMJ(n,m)          for(int j=n;j<m;j++)
#define RFROM(n,m)          for(int i=n-1;i>=m;i--)
#define INVERT_FOR(n)       for(int i=0,j=n-1;i<n-1 && j>0;i++,j--)
#define STL_FOR(a)          for(auto i=a.begin();i!=a.end();i++)
#define STL_FORJ(a)         for(auto j=a.begin();j!=a.end();j++)
#define STL_FROM(a,n,m)     for(auto i=n;i!=m;i++)
#define STL_FROMJ(a,n,m)    for(auto j=n;j!=m;j++)
#define REVERSE_STL_FOR(a)  for(auto i=a.rbegin();i!=a.rend();i++)
#define REVERSE_STL_FORJ(a) for(auto j=a.rbegin();j!=a.rend();j++)  
//math
/*#define min(a,b) a<b ? true:false
#define max(a,b) a>b ? true:false*/


//Short naming
#define read(n)\
cin>>n
#define write(n)\
cout<<n<<endl
#define FAST_IO()\
ios_base::sync_with_stdio(false);\
cin.tie(NULL);\
cout.tie(NULL)


//types
typedef long long int          ll;// -(2^63) to (2^63)-1
typedef unsigned int         uint;//     0 to 4294967295
typedef short int            sint;//     -32768 to 32767
typedef unsigned short int  suint;//         0 to 65,535
#define vec                 vector
#define veci           vector<int>
#define pb               push_back
#define umap         unordered_map
#define ummap   unordered_multimap
#define mmap              multimap
#define mset              multiset
#define uset         unordered_set
#define umset   unordered_multiset

//type conversions
#define INT(n)              (int)n
#define CHAR(n)            (char)n
#define C(type,n)          (type)n
#define TOLOWER(n) CHAR(INT(n-32))

//Template classes
template<typename t_mat>
class mat
{
    uint32_t rowSize;
    uint32_t colSize;

    t_mat* m_mat;

public:

    mat()=default;
    mat(uint32_t rowSize, uint32_t colSize)
    {
        this->rowSize=rowSize;
        this->colSize=colSize;

        m_mat=new t_mat[rowSize*colSize];
    }

    ~mat()
    {
        delete[] m_mat;
    }

    size_t size() const
    {
        return rowSize * colSize;
    }

    uint32_t row_size()
    {
        return rowSize;
    }

    uint32_t col_size()
    {
        return colSize;
    }

    t_mat* operator [](int rowIndex)
    {
        return &m_mat[rowIndex * colSize];
    }
    const t_mat* operator [](int colIndex) const  
    {
        return *m_mat[colIndex * colSize];
    }

    friend istream& operator>> (istream& input, mat& self)
    {
        t_mat n;
        FOR(self.size())
        {
            input>>n;
            self.m_mat[i]=n;
        }

        return input;
    }

    friend ostream& operator<< (ostream& output,mat& self)
    {
        FOR(self.rowSize){
            FORJ(self.colSize)
            {
                output<<self[i][j]<<' ';
            }output<<'\n';
        }

        return output;
    }


};

template<typename t_arr>
class arr
{
    size_t arrSize;
    t_arr* m_arr;

public:
    arr()=default;
    arr(size_t arrSize)
    {
        this->arrSize=arrSize;

        m_arr=new t_arr[arrSize];
    }

    ~arr()
    {
        delete[] m_arr;
    }

    inline size_t size()
    {
        return arrSize;
    }

    inline t_arr& operator[] (uint32_t index) const
    {
        return m_arr[index];
    }

    friend istream& operator>> (istream& input,arr& self)
    {
        t_arr n;
        FOR(self.size())
        {
            input>>n;
            self[i]=n;
        }

        return input;
    }

    friend ostream& operator<< (ostream& output,arr& self)
    {
        FOR(self.size())
        {
            output<<self[i]<<'\n';
        }

        return output;
    }
 

};


//----------------------------------------------------------------------------------------------


struct weighted_edge
{
    int edge;
    int weight;
};

class graph
{
    list<int>* adj;

    int vertcount,edgecount;

public:

    graph()=default;
    graph(int vertcount,int edgecount)
    {
        adj=new list<int>[vertcount];

        this->vertcount=vertcount;
        this->edgecount=edgecount;

    }
    ~graph(){delete[] adj;}

    void insert(int vert, int edge)
    {
        adj[vert].pb(edge);
        adj[edge].pb(vert);
    }

    friend istream& operator>> (istream& input, graph& self)
    {
        int vert, edge;
       
        FOR(self.edgecount)
        {
            input>>vert>>edge;
            self.insert(vert,edge);
        }

        return input;
    }

    veci bfs(int& s);
    void dfs(int& s);
};


int dfs(arr<int>& a, int n , int i, int j, int k)
{
    if(i==j)
        return n;

    if(k==1)
        return max(n-a[j], a[j]-n);

    int i1=i,j1=j;


    int x=dfs(a, n-a[j],i, j + ( i<j ? -1:1 ), k-1 );
    int y=dfs(a, a[j]-n, j, i+ ( i<j ? 1:-1 ) , k-1);

    return max(x, y);
}

void result()
{
    int n,k;
    cin>>n>>k;

    arr<int> a(n);
    cin>>a;

    cout<<dfs(a,a[0], 0, n-1, k-1)<<endl;
}

int main()
{
    FAST_IO();
    result();
}