N, K = map(int, input().split()) A = list(map(int, input().split())) if A[K - 1] == 0: print(0) exit() p = K - 2 for i in range(K - 2, -1, -1): if A[i] <= 1: p = i break else: p = 0 q = K for i in range(K, N): if A[i] <= 1: q = i break else: q = N - 1 #print(p, q) if A[K - 1] > 1: ans = 0 for i in range(p, q + 1): ans += A[i] print(ans) else: ans1 = 0 for i in range(p, K): ans1 += A[i] ans2 = 0 for i in range(K - 1, q + 1): ans2 += A[i] print(max(ans1, ans2))