N, K = map(int, input().split()) X = list(map(int, input().split())) if X[K-1] == 0: print(0) elif X[K-1] == 1: a = 0 for i in range(K, N): a += X[i] if X[i] <= 1: break b = 0 for i in range(max(0, K-2)): b += X[i] if X[i] <= 1: break print(1+max(a, b)) else: a = 0 for i in range(K, N): a += X[i] if X[i] <= 1: break b = 0 for i in range(max(0, K-2)): b += X[i] if X[i] <= 1: break print(a+b+X[K-1])