#include <bits/stdc++.h>
using namespace std;
int N, K;
int A[200];
int inside[200], outside[200];
int main(int argc, char** argv) {
  std::ios::sync_with_stdio(false);
  cin >> N >> K;
  int mx = -100000;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    mx = max(mx, A[i]);
  }
  int ans;
  if (mx <= 0) {
    ans = mx;
  } else {
    ans = 0;
    for (int i = 0; i < N; i++) {
      for (int j = i; j < N; j++) {
        if (i == 2 && j == 7) {
          cout << "";
        }
        int sum = 0;
        for (int k = i; k <= j; k++) sum += A[k];
        int in = 0, ou = 0;
        for (int k = 0; k < N; k++) {
          if (i <= k && k <= j)
            inside[in++] = A[k];
          else
            outside[ou++] = A[k];
        }
        sort(inside, inside + in);
        sort(outside, outside + ou, greater<int>());
        for (int k = 0; k < min(K, min(in, ou)); k++) {
          if (outside[k] <= inside[k]) break;
          sum += outside[k] - inside[k];
        }
        ans = max(ans, sum);
      }
    }
  }
  cout << ans << endl;
  return 0;
}
