#include <bits/stdc++.h>
using namespace std;
const int N = 2e6 + 1;
const int INF = 1e9 + 9;
const int B = 1e9 + 7;
int n, k, a[N];
int main() {
  ios_base ::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> k;
  for (int i = int(1); i <= int(n); ++i) cin >> a[i];
  long long ans = 0;
  for (int i = int(1); i <= int(n - k); ++i)
    if (a[i] > 0) ans += a[i];
  long long mx = 0, s = 0;
  for (int i = int(n); i >= int(n - k + 1); --i) mx = max(mx, s += a[i]);
  ans += mx;
  cout << ans << "\n";
  return 0;
}
