#include <bits/stdc++.h>
using namespace std;
int n, k;
int niz[1000000];
int main() {
  cin >> n >> k;
  for (int i = 0; i < n; ++i) cin >> niz[i];
  int sol = 0;
  int sol2 = 0;
  for (int i = k; i < n - k; ++i) {
    if (niz[i] > 0) {
      sol += niz[i];
      sol2 += niz[i];
    }
  }
  int br1 = 0, br2 = 0;
  for (int i = n - k; i < n; ++i) {
    if (niz[i] > 0) sol += niz[i];
    br2 += niz[i];
  }
  for (int i = 0; i < k; ++i) {
    if (niz[i] > 0) sol2 += niz[i];
    br1 += niz[i];
  }
  if (br1 > 0) sol += br1;
  if (br2 > 0) sol2 += br2;
  cout << max(sol, sol2);
  return 0;
}
