```#include<bits/stdc++.h>
using namespace std;
int main()
{
int n , k;
cin >> n >>k;
int pl =2*k;
vector<int>prices(n,0);
for(int i = 0;i<n;i++)
cin >> prices[i];
vector<vector<int> >dp(n,vector<int>(pl+1,0));
dp[0][0] = 0;
for(int i =1;i<pl;i+=2)
dp[0][i]=-prices[0];
for(int i =1;i<n;i++)
for(int j =0;j<pl;j+=2)
{
dp[i][j+1] = max(dp[i-1][j+1],dp[i-1][j]-prices[i]);
dp[i][j+2] = max(dp[i-1][j+2],dp[i-1][j+1]+prices[i]);
}
if(dp[n-1][pl])cout<<dp[n-1][pl];
else cout<<"0";
return 0;
}