#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, a[205], b[205];
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    int Max = -1111111111;
    for (int i = 1; i <= n; i++) {
      for (int j = i; j <= n; j++) {
        int sum = 0;
        for (int k = 1; k <= n; k++) {
          b[k] = a[k];
          if (k >= i && k <= j) sum += a[k];
        }
        for (int k = 0; k < m; k++) {
          sort(b + i, b + j + 1);
          int p1 = -1, Mmax = -1111111;
          for (int k1 = 1; k1 < i; k1++) {
            if (Mmax < b[k1]) {
              Mmax = b[k1];
              p1 = k1;
            }
          }
          for (int k1 = j + 1; k1 <= n; k1++) {
            if (Mmax < b[k1]) {
              Mmax = b[k1];
              p1 = k1;
            }
          }
          if (Mmax > b[i]) {
            sum = sum + Mmax - b[i];
            swap(b[i], b[p1]);
          }
          if (sum > Max) Max = sum;
        }
      }
    }
    cout << Max << endl;
  }
  return 0;
}
