#include <bits/stdc++.h>
int n, k;
int a[300];
std::vector<std::pair<int, int> > v;
std::pair<int, int> temp;
std::multiset<int> s;
std::multiset<int>::iterator it;
std::vector<int> ka;
int suma;
bool cmp(std::pair<int, int> a, std::pair<int, int> b) {
  return a.first > b.first;
}
void Brisi() {
  it = s.end();
  --it;
  s.erase(it);
}
int rez = -90000000;
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  v.resize(n);
  for (int i = 0; i < n; ++i) {
    temp.first = a[i];
    temp.second = i;
    v[i] = temp;
  }
  std::sort(v.begin(), v.end(), cmp);
  for (int l = 0; l < n; ++l) {
    for (int r = l; r < n; ++r) {
      s.clear();
      ka.clear();
      suma = 0;
      for (int i = l; i <= r; ++i) {
        suma += a[i];
        if (a[i] < 0) s.insert(a[i]);
        if (s.size() > k) Brisi();
      }
      if (s.empty()) {
        rez = std::max(rez, suma);
        continue;
      }
      for (int i = 0; (i < n) && (ka.size() < k); ++i) {
        if (v[i].second < l || v[i].second > r) ka.push_back(v[i].first);
      }
      for (int i = 0; i < ka.size() && !s.empty(); ++i) {
        if (ka[i] > *s.begin()) {
          suma -= *s.begin();
          suma += ka[i];
          s.erase(s.begin());
        } else {
          s.erase(s.begin());
          --i;
        }
      }
      rez = std::max(rez, suma);
    }
  }
  printf("%d\n", rez);
}
