#include <bits/stdc++.h>
using namespace std;
void openFile() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
}
const int maxn = (int)4e2 + 5;
const int maxm = (int)50 + 5;
const long long inf = (long long)1e9 + 7;
int N, K;
int a[maxn], s[maxn];
int f[maxn][maxn][maxm];
void enter() {
  cin >> N >> K;
  for (int i = 1; i <= N; ++i) {
    cin >> a[i];
  }
}
inline int getSum(int i, int j) { return s[j] - s[i - 1]; }
void prepare() {
  fill_n(&f[0][0][0], maxn * maxn * maxm, -1);
  for (int i = 1; i <= N; ++i) {
    s[i] = s[i - 1] + a[i];
  }
  for (int i = 1; i <= N; ++i) {
    for (int j = i; j <= N; ++j) {
      f[i][j][1] = 0;
    }
  }
}
void solve() {
  for (int i = 1; i <= N; ++i) {
    for (int j = i; j <= N; ++j) {
      for (int k = 1; k < K; ++k)
        if (f[i][j][k] != -1) {
          auto smin = 0;
          auto smax = 0;
          int pmin = j, pmax = j;
          for (int v = j + 1; v <= N; ++v) {
            ((f[pmax + 1][v][k + 1]) <
                 (f[i][j][k] + abs(getSum(i, j) - getSum(pmax + 1, v)))
             ? (f[pmax + 1][v][k + 1]) =
                   (f[i][j][k] + abs(getSum(i, j) - getSum(pmax + 1, v))),
             1 : 0);
            ((f[pmin + 1][v][k + 1]) <
                 (f[i][j][k] + abs(getSum(i, j) - getSum(pmin + 1, v)))
             ? (f[pmin + 1][v][k + 1]) =
                   (f[i][j][k] + abs(getSum(i, j) - getSum(pmin + 1, v))),
             1 : 0);
            if (((smin) > (getSum(j + 1, v)) ? (smin) = (getSum(j + 1, v)),
                 1                           : 0)) {
              pmin = v;
            }
            if (((smax) < (getSum(j + 1, v)) ? (smax) = (getSum(j + 1, v)),
                 1                           : 0)) {
              pmax = v;
            }
          }
        }
    }
  }
  int res = 0;
  for (int i = 1; i <= N; ++i) {
    for (int j = i; j <= N; ++j) {
      ((res) < (f[i][j][K]) ? (res) = (f[i][j][K]), 1 : 0);
    }
  }
  cout << res << endl;
}
int main() {
  openFile();
  enter();
  prepare();
  solve();
  return 0;
}
