import sys sys.setrecursionlimit(10 ** 8) input = sys.stdin.readline def main(): N, K = [int(x) for x in input().split()] A = [int(x) for x in input().split()] if A[K - 1] == 0: print(0) return ans1 = 0 for a in A[K:]: if a < 2: ans1 += a break ans1 += a ans2 = 0 for i in range(K - 2, -1, -1): a = A[i] if a < 2: ans2 += a break ans2 += a if A[K - 1] == 1: print(max(ans1, ans2) + A[K - 1]) else: print(ans1 + ans2 + A[K - 1]) if __name__ == '__main__': main()