#include <bits/stdc++.h>
using namespace std;
int n, a[500], s[500], Q, f[500][60][500];
int main() {
  cin >> n >> Q;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    s[i] = s[i - 1] + a[i];
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 2; j <= min(i, Q); j++) {
      for (int k = 1; k <= i - j + 1; k++) {
        for (int 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]);
      }
    }
  }
  cout << ans << '\n';
}
