#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <algo/debug.h>
#else
#define debug(...) 42
#endif

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  priority_queue<int, vector<int>, greater<int>> big;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  long long ans = 0;
  long long sum = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (i % 2 == 1 && big.size() == k - 1) {
      ans = max(ans, sum + a[i]);
    }
    if (big.size() < k - 1) {
      big.push(a[i]);
      sum += a[i];
    } else {
      if (!big.empty() && big.top() < a[i]) {
        int top = big.top(); big.pop();
        big.push(a[i]);
        sum += a[i] - top;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}