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() if N == 2: print(A[-1]) exit() l,r = 1,N-1 for i in range(K+1,N): if A[i] == 0 or A[i] == 1: r = i break for i in range(K-1,-1,-1): if A[i] == 1 or (i != 0 and A[i] == 0): 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)