N,K = map(int, input().split()) A = [int(a) for a in input().split()] if A[K-1] > 0: ans = A[K-1] for i in range(K, N): ans += A[i] if A[i] < 2: break for i in range(K-2, -1, -1): ans += A[i] if A[i] < 2: break else: ans = 0 print(ans)