#include <bits/stdc++.h>
using namespace std;
int n, k;
int a[207], b[207], id[207];
int main() {
  cin >> n >> k;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    id[i] = i;
    b[i] = a[i];
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j < n; j++) {
      if (a[j] > a[j + 1]) {
        int temp = a[j];
        a[j] = a[j + 1];
        a[j + 1] = temp;
        temp = id[j];
        id[j] = id[j + 1];
        id[j + 1] = temp;
      }
    }
  }
  int res = -1007;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j++) {
      int temp = 0;
      for (int t = i; t <= j; t++) temp += b[t];
      int id_ = n;
      int count_ = k;
      while (id_ >= 1 && count_ > 0) {
        if (id[id_] > j || id[id_] < i) {
          if (temp + a[id_] > temp) {
            temp = temp + a[id_];
            count_--;
          } else
            break;
        }
        id_--;
      }
      count_ = k - count_;
      for (int t = 1; t <= n; t++) {
        if (id[t] >= i && id[t] <= j && count_ > 0) {
          temp -= a[t];
          count_--;
        }
        if (count_ == 0) break;
      }
      res = max(res, temp);
    }
  }
  cout << res << endl;
}
