#include <bits/stdc++.h>
using namespace std;
int a[500], s[500], f[500][60][500];
int n, q;
inline int solve() {
  int ans = 0;
  int i, j, k, t;
  for (i = 1; i <= n; i++) {
    for (j = 2; j <= min(i, q); j++) {
      for (k = 1; k <= i - j + 1; k++) {
        for (t = 1; t <= i - k - j + 2; t++)
          f[i][j][k] = max(f[i][j][k],
                           f[i - k][j - 1][t] +
                               abs(s[i] - s[i - k] - s[i - k] + s[i - k - t]));
        if (j == q) ans = max(ans, f[i][j][k]);
      }
    }
  }
  return ans;
}
int main() {
  scanf("%d%d", &n, &q);
  int i;
  for (i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    s[i] = s[i - 1] + a[i];
  }
  printf("%d", solve());
}
