#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
int arr[MAX];
int main() {
  int n, k;
  scanf("%d %d", &n, &k);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &arr[i]);
  }
  long long sum = 0;
  for (int i = 1; i <= k; i++) {
    sum += arr[i];
  }
  sum = max(0ll, sum);
  for (int i = k + 1; i <= n; i++) {
    if (arr[i] > 0) {
      sum += arr[i];
    }
  }
  ans = max(ans, sum);
  sum = 0;
  for (int i = n; i >= (n - k + 1); i--) {
    sum += arr[i];
  }
  sum = max(sum, 0ll);
  for (int i = n - k; i >= 1; i--) {
    if (arr[i] > 0) {
      sum += arr[i];
    }
  }
  ans = max(ans, sum);
  printf("%lld\n", ans);
}
