n, k = map(int, input().split()) a = list(map(int, input().split())) b = bytes(i > 1 for i in a) print(sum((sorted([ sum(a[b.rfind(0, 0, k-1)-n:k-1]), sum(a[b.find(0, k):k-1:-1]) ])+[a[k-1]])[-1-a[k-1]:]))