n, k = list(map(int,input().split()))
a = list(map(int,input().split()))
l = [i for i in a if i>0]
ans = sum(l)
t = 0
for i in range(k):
    t += a[i]
c = 0
import sys
for i in range(k,n):
    f = True
    for j in range(k):
        if a[i-j]>=0:
            f = False
            break
    if f:
        print(ans)
        sys.exit()
    if a[i]>a[i-k]:
        c = i
        t += a[i]-a[i-k]
a = a[:c-k]+a[c+1:]
l = [i for i in a if i>0]
print(sum(l)+t)
