line = gets
line = line.split(" ")
N = line[0].to_i
K = line[1].to_i
line = gets
line = line.split(" ")
a = []
b = []
for i in 1..N
	a[i] = line[i-1].to_i
end
result = 0
for i in 1..N-K
	if a[i]>=0
		result+=a[i]
		b[i] = 1
	else
		b[i] = 0
	end
end
lastsum = 0
for i in N-K+1..N
	lastsum+=a[i]
end
if lastsum>=0
	result+=lastsum
	for i in N-K+1..N
		b[i] = 1
	end
else
	for i in N-K+1..N
		b[i] = 0
	end
end #最初の色塗り

for i in N-2*K+2..N-K
	sum1 = 0
	sum2 = 0
	for j in 0..K-1
		if b[i+j] == 1
			sum1 += -a[i+j]
		else
			sum2 += a[i+j]
		end
	end
	if sum1>0 || sum2>0
		if sum1>sum2
			result += sum1
		else
			result += sum2
		end
		break
	end
end
print( result )