#include <bits/stdc++.h>
intmax_t simulate(const std::vector<intmax_t> &a, size_t K) {
  intmax_t res = 0;
  intmax_t cur = 0;
  size_t N = a.size();
  for (size_t i = 0; i < N - K + 1; ++i) cur += std::max<intmax_t>(0, a[i]);
  intmax_t rest = 0;
  for (size_t i = N - K + 1; i < N; ++i) rest += a[i];
  cur += std::max<intmax_t>(0, rest);
  res = std::max(res, cur);
  return res;
}
int main() {
  size_t N, K;
  scanf("%zu %zu", &N, &K);
  std::vector<intmax_t> a(N);
  for (size_t i = 0; i < N; ++i) scanf("%jd", &a[i]);
  intmax_t res = simulate(a, K);
  std::reverse(a.begin(), a.end());
  res = std::max(res, simulate(a, K));
  printf("%jd\n", res);
}
