#include<iostream>
#include<algorithm>
#include<string>
#define LL long long
int N, K;
LL ans;
LL a[100010];
bool D[100010];
int main() {
	std::cin >> N >> K;
	for (int i = 0; i < N; i++) {
		std::cin >> a[i];
	}
	for (int i = 0; i < N - K; i++) {
		if (a[i] > 0) {
			ans += a[i];
		}
	}
	LL add = 0;
	LL bdd = 0;
	for (int i = N - K; i < N; i++) {
		if (D[i])add += a[i];
		bdd += a[i];
	}
	ans += std::max(add, bdd, 0);
	std::cout << ans << std::endl;
}