#include <bits/stdc++.h>
using namespace std;
const double PI = 3.14159265358979323846;
const double EPS = 1e-9;
const int INF = 2e9;
const long long LINF = 1e18;
template <class T>
const T sqr(const T &x) {
  return x * x;
}
template <class T>
const T &min(const T &a, const T &b, const T &c) {
  return min(min(a, b), c);
}
template <class T>
const T &max(const T &a, const T &b, const T &c) {
  return max(max(a, b), c);
}
struct DbgStream {
  template <class T>
  DbgStream &operator<<(const T &x) {
    return *this;
  }
} z_dbg;
int n, k, a[500], ans = -INF;
multiset<int, greater<int> > s;
multiset<int> s2;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> k;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = i + 1; j <= n; ++j) {
      int ms = 0, o = 0;
      for (int z = 0; z < n; ++z) {
        if (i <= z && z < j)
          s2.insert(a[z]), ms += a[z];
        else
          s.insert(a[z]);
      }
      while (o < k && s.size() && s2.size() && *s2.begin() < *s.begin()) {
        ms -= *s2.begin();
        s2.erase(s2.begin());
        ms += *s.begin();
        s.erase(s.begin());
        ++o;
      }
      ans = max(ans, ms);
      s.clear();
      s2.clear();
    }
  }
  cout << ans << "\n";
  return 0;
}
