#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 9;
void insert_ascending(list<int> &l, unsigned int k, int value) {
  bool done = false;
  for (auto it = l.begin(); it != l.end(); it++) {
    if (*it > value) {
      l.insert(it, value);
      done = true;
      break;
    }
  }
  if (!done) {
    l.insert(l.end(), value);
  }
}
void insert_decending(list<int> &l, unsigned int k, int value) {
  bool done = false;
  for (auto it = l.begin(); it != l.end(); it++) {
    if (*it < value) {
      l.insert(it, value);
      done = true;
      break;
    }
  }
  if (!done) {
    l.insert(l.end(), value);
  }
}
int calculate(list<int> &in, list<int> &out, int k, int base_sum) {
  auto it1 = in.begin(), it2 = out.begin();
  for (int i = 0; i < k && it1 != in.end() && it2 != out.end();
       i++, it1++, it2++) {
    if (*it1 < *it2) {
      base_sum += (*it2 - *it1);
    }
  }
  return base_sum;
}
void remove_first(list<int> &l, int value) {
  auto it = find(l.begin(), l.end(), value);
  if (it != l.end()) l.erase(it);
}
int main(int argc, char *argv[]) {
  unsigned int n, k;
  cin >> n >> k;
  vector<int> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
  }
  int ans = -1e9;
  for (unsigned int len = 1; len <= n; len++) {
    int base_sum = 0;
    list<int> in, out;
    for (int i = 0; i < n && i < len; i++) {
      insert_ascending(in, k, v[i]);
      base_sum += v[i];
    }
    for (int i = len; i < n; i++) {
      insert_decending(out, k, v[i]);
    }
    ans = max(ans, calculate(in, out, k, base_sum));
    for (unsigned int l = 1; l <= n - len; l++) {
      int r = l + len - 1;
      remove_first(in, v[l - 1]);
      remove_first(out, v[r]);
      base_sum += (v[r] - v[l - 1]);
      insert_ascending(in, k, v[r]);
      insert_decending(out, k, v[l - 1]);
      ans = max(ans, calculate(in, out, k, base_sum));
    }
  }
  cout << ans << '\n';
  return 0;
}
