#include <iostream>
#include <algorithm>
using namespace std;
using i64 = long long;

class range {private: struct I{int x;int operator*(){return x;}bool operator!=(I& lhs){return x<lhs.x;}void operator++(){++x;}};I i,n;
public:range(int n):i({0}),n({n}){}range(int i,int n):i({i}),n({n}){}I& begin(){return i;}I& end(){return n;}};

const int inf = 987654321;
int n, m;
vector<int> w;
//vector<vector<vector<vector<int>>>> dp;
int dp[2][2][3005][3005];

// i番目まで見た。j個の頂点を取った。before: 前を取った? first: 最初を取った?
// 最大の価値を返す。
int rec(int i, int j, bool before, bool first) {
//  int &res = dp[i][j][before][first];
  int &res = dp[before][first][i][j];
  if(i==n) {
    if(j==m) {
      return res = (before&&first ? w[i-1] : 0);
    } else {
      return res = -inf;
    }
  }
  if(res != -1) { return res; }
  res = -inf;
  // 前を取ってた
  if(before) {
    // i番目を取る
    if(j < m) { res = max(res, rec(i+1, j+1, true, first) + w[i-1]); }
    // 取らない
    res = max(res, rec(i+1, j, false, first));
  // 前を取ってない
  } else {
    // i番目を取る
    if(j < m) { res = max(res, rec(i+1, j+1, true, first)); }
    // 取らない
    res = max(res, rec(i+1, j, false, first));
  }
  return res;
}

int main(void) {
  scanf("%d%d", &n, &m);
  w.assign(n, 0);
  for(int i : range(3005)) for(int j : range(3005)) for(int k : range(2)) for(int L : range(2)) dp[k][L][i][j] = -1;
//  dp.assign(n+10, vector<vector<vector<int>>>(m+10, vector<vector<int>>(2, vector<int>(2, -1))));
  for(int i : range(n)) { scanf("%d", &w[i]); }
  int res = max(rec(1, 1, 1, 1), rec(1, 0, 0, 0));
  printf("%d\n", res);
  return 0;
}