#include <bits/stdc++.h>   using namespace std;   int n, k, s[444], dp[444][55][444];   int main() {     cin >> n >> k;     s[0] = 0;     for (int i = 1; i <= n; i++) cin >> s[i], s[i] += s[i - 1];     int ans = 0;     for (int i = 1; i <= n; i++)       for (int j = 2; j <= min(i, k); j++)         for (int l = 1; l <= i - j + 1; l++)           for (int h = 1; h <= i - l - j + 2; h++)             dp[i][j][l] =                 max(dp[i][j][l], dp[i - l][j - 1][h] +                                      abs(s[i] + s[i - l - h] - 2 * s[i - l]));     for (int i = 1; i <= n; i++)       for (int j = 1; j <= i - k + 1; j++) ans = max(ans, dp[i][k][j]);     cout << ans << endl;     return 0;   }   