#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k, ans = -1000000000;
  cin >> n >> k;
  int a[10000];
  int b[10000];
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int l = 0; l < n; l++)
    for (int r = l; r < n; r++) {
      for (int i = 0; i < n; i++) b[i] = a[i];
      for (int i = 0; i < k; i++) {
        int min = 10000000, max = -10000000, nmin, nmax;
        for (int j = l; j <= r; j++)
          if (b[j] < min) {
            min = b[j];
            nmin = j;
          }
        for (int j = 0; j < n; j++)
          if ((j < l || j > r) && b[j] > max) {
            max = b[j];
            nmax = j;
          }
        if (min < max) {
          int x = b[nmax];
          b[nmax] = b[nmin];
          b[nmin] = x;
        }
      }
      int sum = 0;
      for (int i = l; i <= r; i++) sum += b[i];
      if (sum > ans) {
        ans = sum;
      }
    }
  cout << ans;
}
