#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[401];
int psum[401];
int dp[401][401][50];
int main() {
  cin >> N >> K;
  for (int i = 0; i < N; i++) cin >> A[i];
  psum[0] = 0;
  for (int i = 0; i < N; i++) psum[i + 1] = psum[i] + A[i];
  for (int k = 1; k <= K; k++)
    for (int i = 1; i <= N; i++)
      for (int j = i; j <= N; j++) dp[i][j][k] = -(1 << 30);
  for (int i = 1; i <= N; i++)
    for (int j = i; j <= N; j++) dp[i][j][1] = 0;
  int bst = 0;
  for (int k = 2; k <= K; k++) {
    int plus = -(1 << 30);
    int minus = -(1 << 30);
    for (int i = 1; i <= N; i++) {
      for (int j = i; j <= N; j++) {
        dp[i][j][k] = max(plus - (psum[j] - psum[i - 1]),
                          minus + (psum[j] - psum[i - 1]));
        if (k == K) bst = max(bst, dp[i][j][k]);
      }
      for (int j = 1; j <= i; j++) {
        plus = max(plus, dp[j][i][k - 1] + (psum[i] - psum[j - 1]));
        minus = max(minus, dp[j][i][k - 1] - (psum[i] - psum[j - 1]));
      }
    }
  }
  cout << bst << endl;
  return 0;
}
