#include <bits/stdc++.h>
const int MAXN = 400 + 5;
int n, k;
int f[55][405][405];
int a[MAXN], sm[MAXN];
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 1; i <= n; ++i) scanf("%d", a + i), sm[i] = sm[i - 1] + a[i];
  memset(f, -0x3f, sizeof(f));
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= i; ++j) f[1][i][j] = 0;
  for (int i = 2; i <= ::k; ++i) {
    for (int j = 1; j <= n; ++j) {
      for (int k = 1; k <= j; ++k) {
        for (int t = 1; t <= k - 1; ++t) {
          f[i][j][k] = std::max(
              f[i][j][k],
              f[i - 1][k - 1][t] +
                  std::abs((sm[j] - sm[k - 1]) - (sm[k - 1] - sm[t - 1])));
        }
      }
    }
  }
  std::cerr << "f[k][5][5]" << '=' << f[k][5][5] << std::endl;
  int ans = 0;
  for (int i = 1; i <= n; ++i)
    for (int j = 1; j <= i; ++j) ans = std::max(ans, f[k][i][j]);
  printf("%d\n", ans);
  return 0;
}
