#include <bits/stdc++.h>
using namespace std;
long long dp[3010];
long long p[3010];
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 1; i <= n; i++) cin >> p[i];
  for (int i = 1; i <= k; i++) {
    long long mx = -1000000000000000000ll;
    long long mx2 = 0;
    for (int j = 1; j <= n; j++) {
      mx = max(mx, mx2 - p[j]);
      mx2 = max(mx2, dp[j]);
      dp[j] = mx + p[j];
    }
  }
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
}
