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

typedef long long ll;
ll moda=1000000007;
typedef vector<ll> vl1;
typedef vector<vl1> vl2;
typedef vector<vl2> vl3;
typedef vector<string> vst1;

struct struka
{ll val; ll ind;};
typedef vector<struka> vs1;

bool compa(struka& a, struka& b)
{ if(a.val==b.val) return a.ind<b.ind;
  return a.val<b.val;
}

ll lova(vl1&  veka, ll dole, ll gore, ll val)
{ ll sred;
  while(dole<=gore)
  {sred=(gore+dole)/2;
   if(veka[sred]>=val) gore=sred-1;// real condition !
   else dole=sred+1;
  }
 return dole;
}

ll gcd(ll a,ll b)
{ll t;
  while (b)
  { t= b;
    b = a % b;
    a = t;
  }
return a;
}

ll fast_pow(ll a, ll p)
{ ll res = 1;
  while (p)
   { if ( (p &1) == 0) { a = (a * a); p >>=1; }
     else {  res *=  a;   p--; }
   }
  return res;
}

void radi(ll& q)
{ ll i, j, k, kn, m, n, p, t, l, r, x, y, z, a, b, c, d;
  ll val, pos, tmp, suma, maxa, mina, naso, num;
  string str1;
  char ch1;
  cin>>n>>kn;
  vl1 niz(n+1);
  for(i=1;i<=n;i++) cin>>niz[i];
  vl3 dpg(n+1, vl2(n+1, vl1(kn+1, INT_MIN)));
  vl3 dpd(n+1, vl2(n+1, vl1(kn+1, INT_MAX)));
  for(j=1;j<kn;j++)
   { for(i=1;i<=n;i++)
      { for(k=1;k<=n;k++)
          { if(k==i) continue;
            if(i>k)
                { val=i-k-1;
                  a=k+j-1; b=i-1;//a is min val of middle
                }
            else
               { val=k-i-1;
                 a=i+1; b=k-(j-1);//b is max of middle
               }
            if(val<j) continue;// nema dovoljno mesta izmedju
            if(j==1) { suma =niz[i]-niz[k];
                       dpg[i][k][1]=suma; //max suma
                       dpd[i][k][1]=suma;//min suma
                       continue;
                     }
            maxa=dpg[k][a][j-1];
            mina=dpd[k][a][j-1];
            for(p=a;p<=b;p++)
             { suma=dpg[k][p][j-1];
               if(suma>maxa) maxa=suma;
               suma=dpd[k][p][j-1];
               if(suma<mina) mina=suma;
             }
            dpg[i][k][j]=niz[i]-mina;
            dpd[i][k][j]=niz[i]-maxa;
          }
      }
   }
  maxa=dpg[1][kn][kn-1];
  for(i=1;i<=n;i++)
   { for(k=1;k<=n;k++)
       { val=i-k;
         if(val<0) val=-val;
         if(val<kn-1) continue;
         if(dpg[i][k][kn-1]>maxa)
            { maxa=dpg[i][k][kn-1];
              //cout<<i<<' '<<k<<' '<<maxa<<'\n';
            }
       }
   }
  cout<<maxa<<'\n';
}

int main()
{ /*
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(nullptr);
  cout<<fixed<<setprecision(15);
  */

  ll t, q;
  //cin>>t;
  t=1;
  for(q=1;q<=t;q++)
   { // cout<<"Case #"<<q<<": ";
     radi(q);
   }
  return 0;
}
/*
3 2
5 3 2

5 3
5 4 3 2 1

7 4
7 6 5 4 3 2 1
*/