#include <bits/stdc++.h>
using namespace std;
int tansa(deque<int> a, int kai, vector<int> hav, int k) {
  if (kai == k) {
    int sm = 0;
    for (int i = 0; hav.size() > i; i++) {
      sm += hav[i];
    }
    return sm;
  }
  int mx = tansa(a, kai + 1, hav, k);
  if (!a.empty()) {
    int hai = a[0];
    hav.push_back(hai);
    sort(hav.begin(), hav.end(), greater<int>());
    a.pop_front();
    mx = max(mx, tansa(a, kai + 1, hav, k));
    a.push_front(hai);
    for (int i = 0; hav.size() > i; i++) {
      if (hai == hav[i]) {
        hav.erase(hav.begin() + i);
        break;
      }
    }
  }
  if (!a.empty()) {
    int hai = a[a.size() - 1];
    hav.push_back(hai);
    sort(hav.begin(), hav.end(), greater<int>());
    a.pop_back();
    mx = max(mx, tansa(a, kai + 1, hav, k));
    a.push_back(hai);
    for (int i = 0; hav.size() > i; i++) {
      if (hai == hav[i]) {
        hav.erase(hav.begin() + i);
        break;
      }
    }
  }
  if (!(hav.empty() || hav[hav.size() - 1] > 0)) {
    int hai = hav[hav.size() - 1];
    a.push_front(hai);
    hav.pop_back();
    mx = max(mx, tansa(a, kai + 1, hav, k));
    hav.push_back(hai);
    a.pop_front();
  }
  if (!(hav.empty() || hav[hav.size() - 1] > 0)) {
    int hai = hav[hav.size() - 1];
    a.push_back(hai);
    hav.pop_back();
    mx = max(mx, tansa(a, kai + 1, hav, k));
    hav.push_back(hai);
    a.pop_back();
  }
  return mx;
}
int main() {
  int n, k;
  cin >> n >> k;
  deque<int> a;
  vector<int> hav;
  for (int i = 0; n > i; i++) {
    int tmp;
    cin >> tmp;
    a.push_back(tmp);
  }
  cout << max(0, tansa(a, 0, hav, k)) << endl;
  return 0;
}
