#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 405;
const int INF = INT_MAX / 2 - 10;
int dp[MAX_N][MAX_N][52];
int acc[MAX_N];
int sum(int i, int j) { return acc[j + 1] - acc[i]; }
int main() {
  int n, k;
  cin >> n >> k;
  int a[n];
  for (int i = 0; i < n; ++i) cin >> a[i];
  acc[0] = 0;
  for (int i = 0; i < n; ++i) acc[i + 1] = acc[i] + a[i];
  for (int i = n - 1, j, left, d, x; i >= 0; --i)
    for (j = n - 1; j > i; --j)
      for (left = 1; left < k; ++left) {
        x = sum(i, j - 1);
        int& r = dp[i][j][left];
        r = -INF;
        if (left == 1) {
          for (d = j; d < n; ++d) r = max(r, abs(x - sum(j, d)));
        } else {
          for (d = j + 1; d < n; ++d)
            r = max(r, abs(x - sum(j, d - 1)) + dp[j][d][left - 1]);
        }
      }
  int ans = 0;
  for (int i = 0; i < n; ++i)
    for (int j = i + 1; j < n; ++j) ans = max(ans, dp[i][j][k - 1]);
  printf("%d\n", ans);
  return 0;
}
