#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, k, tmp;
  vector<int> v, motimono, ans;
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    v.push_back(tmp);
  }
  if (k >= n) {
    k -= n;
    ans.push_back(accumulate(v.begin(), v.end(), 0));
    sort(v.begin(), v.end());
    for (int i = 0; i < k; i++) {
      for (int j = 0; j < min<unsigned long>(k, n); i++) {
        v[j] = 0;
        ans.push_back(accumulate(v.begin(), v.end(), 0));
      }
    }
  } else {
    for (int i = 0; i < n; i++) {
      v.push_back(v[i]);
    }
    for (int j = 1; j < k + 1; j++) {
      for (int i = n - j; i < n + 1; i++) {
        vector<int> motimono;
        for (int r = i; r < i + j; r++) {
          motimono.push_back(v[r]);
        }
        ans.push_back(accumulate(motimono.begin(), motimono.end(), 0));
        sort(motimono.begin(), motimono.end());
        for (int i = 0; i < min<unsigned long>(k - j, motimono.size()); i++) {
          motimono[i] = 0;
          ans.push_back(accumulate(motimono.begin(), motimono.end(), 0));
        }
      }
    }
  }
  cout << *max_element(ans.begin(), ans.end()) << endl;
}
