#include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
  return x * x;
}
template <class T>
T abs(T x) {
  return x < 0 ? -x : x;
}
const int MAXN = 5 * 1000;
long long p[MAXN], b[MAXN];
long long a[MAXN][MAXN / 2][2];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n; ++i) {
    scanf("%I64d", &p[i]);
  }
  for (int i = 0; i < n - 1; ++i) {
    b[i] = p[i + 1] - p[i];
  }
  for (int j = 0; j <= k; ++j) {
    a[0][j][0] = -inf;
    a[0][j][1] = -inf;
  }
  a[0][0][0] = 0;
  for (int i = 1; i < n; ++i) {
    a[i][0][0] = 0;
    a[i][0][1] = -inf;
    for (int j = 1; j <= k; ++j) {
      a[i][j][0] = max(a[i - 1][j][0], a[i - 1][j][1]);
      a[i][j][1] = max(a[i - 1][j][1], a[i - 1][j - 1][0]) + b[i - 1];
    }
  }
  long long ans = -inf;
  for (int j = 0; j <= k; ++j) {
    ans = max(ans, max(a[n - 1][j][1], a[n - 1][j][0]));
  }
  cout << ans << endl;
  return 0;
}
