import sys input = lambda: sys.stdin.readline().rstrip() ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) inf = 2 ** 63 - 1 mod = 998244353 class segtree(): n=1 size=1 log=2 d=[0] op=None e=10**15 def __init__(self,V,OP,E): self.n=len(V) self.op=OP self.e=E self.log=(self.n-1).bit_length() self.size=1<>i) def get(self,p): assert 0<=p and p>=1 r>>=1 return self.op(sml,smr) def all_prod(self): return self.d[1] def update(self,k): self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def __str__(self): return str([self.get(i) for i in range(self.n)]) def solve_gu(n, k, a): ans = 0 for bit in range(1<> i): ch[i] = a[i] now = sum(ch) for i in range(n - k + 1): fl = True for j in range(k): if ch[i + j] == 0: fl = False if fl: now = 0 if now > 0: ans = max(ans, now) return ans def solve(n, k, a): if n <= 20: return solve_gu(n, k, a) inf = 10 ** 18 dp = segtree([inf] * (n + 2), min, inf) dp[0] = 0 a.append(0) for i in range(1, n + 2): dp[i] = dp[max(0, i - k):i] + a[i-1] a.pop() return sum(a) - dp[n+1] n, k = mi() a = li() print(solve(n, k, a))