N,K = map(int, input().split()) A = list(map(int, input().split())) r=K-1 l=K-1 if A[K-1]>=2: while l>=1 and A[l]>=2 and A[l-1]>=1: l-=1 while r=2 and A[r+1]>=1: r+=1 print(sum(A[l:r+1])) elif A[K-1]==0: print(0) else: A[K-1]+=1 while l>=1 and A[l]>=2 and A[l-1]>=1: l-=1 while r=2 and A[r+1]>=1: r+=1 print(max(sum(A[l:K]),sum(A[K-1:r+1]))-1)