#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, K, a[200], sorta[200], sum[200][200];
  cin >> n >> K;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    sorta[i] = a[i] * n;
    if (sorta[i] < 0)
      sorta[i] -= i;
    else
      sorta[i] += i;
  }
  sort(sorta, sorta + n);
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      sum[i][j] = 0;
      for (int k = i; k <= j; k++) sum[i][j] += a[k];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      int m = 0, M = n - 1, mm, MM;
      for (int k = 0; k < K; k++) {
        mm = sorta[m] % n;
        if (mm < 0) mm *= -1;
        while (mm < i || mm > j) {
          m++;
          mm = sorta[m] % n;
          if (mm < 0) mm *= -1;
          if (M < m) break;
        }
        MM = sorta[M] % n;
        if (MM < 0) MM *= -1;
        while (MM >= i && MM <= j) {
          M--;
          MM = sorta[M] % n;
          if (MM < 0) MM *= -1;
          if (M < m) break;
        }
        if (M < m) break;
        sum[i][j] += (a[MM] - a[mm]);
        m++;
        M--;
      }
    }
  }
  int S = sum[0][0];
  for (int i = 0; i < n; i++) {
    for (int j = i; j < n; j++) {
      if (S < sum[i][j]) S = sum[i][j];
    }
  }
  cout << S << endl;
}
