#include <bits/stdc++.h>
using namespace std;
bool check(int n, int m, int x, int y) {
  return (x < 0 || x >= n || y < 0 || y >= m) ? false : true;
}
const long long MAX = 1000000007, MAXL = 1LL << 60, dx[4] = {-1, 0, 1, 0},
                dy[4] = {0, 1, 0, -1};
int main() {
  int n, k;
  cin >> n >> k;
  int a[n], d[n + 1];
  d[0] = 0;
  for (int i = (int)(0); i < (int)(n); i++) {
    cin >> a[i];
    d[i + 1] = d[i] + a[i];
  }
  int dp[k + 1][n + 1][n + 1], ans = 0;
  memset(dp, -1, sizeof(dp));
  for (int j = 0; j <= n; j++) {
    for (int i = 1; i <= n; i++) dp[1][j][i] = 0;
  }
  for (int i = 1; i < k; i++) {
    for (int j = 0; j < n; j++) {
      for (int j2 = j + 1; j2 <= n; j2++) {
        if (dp[i][j][j2] != -1) {
          for (int l = (int)(j2 + 1); l < (int)(n + 1); l++) {
            dp[i + 1][j2][l] =
                max(dp[i + 1][j2][l],
                    dp[i][j][j2] + abs((d[j2] - d[j]) - (d[l] - d[j2])));
            if (i + 1 == k) ans = max(ans, dp[i + 1][j2][l]);
          }
        }
      }
    }
  }
  cout << (ans) << endl;
  return 0;
}
