from itertools import accumulate N,K = map(int,input().split()) N += 1 A = [0]+list(map(int,input().split())) if A[K] == 0: print(0) exit() l,r = 1,N for i in range(K,N): if A[i] == 0 or A[i] == 1: r = i break for i in range(K,-1,-1): if A[i] == 1: l = i break AC = list(accumulate(A)) if A[K] == 1: ans = max(AC[r]-AC[K-1],AC[K]-AC[l-1]) else: ans = AC[r]-AC[l-1] print(ans)