#include <bits/stdc++.h>
using namespace std;
const int MAXN = 444;
const int MAXK = 55;
const int INF = 1e9;
int dp[MAXN][MAXN][MAXK];
int a[MAXN], s[MAXN];
int main() {
  std::ios::sync_with_stdio(false);
  memset(dp, 0, sizeof(dp));
  int N, K;
  cin >> N >> K;
  ++N;
  ++K;
  s[0] = 0;
  for (int i = 1; i < N; ++i) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i < N; ++i) {
    for (int j = i; j < N; ++j) {
      for (int k = 2; k < K; ++k) {
        dp[i][j][k] = -INF;
      }
    }
  }
  for (int i = 2; i < N; ++i) {
    for (int j = i; j < N; ++j) {
      for (int k = 2; k < K; ++k) {
        for (int l = 1; l < i; ++l) {
          dp[i][j][k] =
              max(dp[i][j][k],
                  dp[l][i - 1][k - 1] + abs(s[j] - 2 * s[i - 1] + s[l - 1]));
        }
      }
    }
  }
  int res = 0;
  for (int i = 1; i < N; ++i) {
    for (int j = i; j < N; ++j) {
      res = max(res, dp[i][j][K - 1]);
    }
  }
  cout << res << endl;
  return 0;
}
