import sys n,k,*a=map(int,sys.stdin.read().split()) k-=1 b=bytes(i>1 for i in a) print(sum(( sorted([sum(a[b.rfind(0,0,k)-n:k]),sum(a[b.find(0,k+1):k:-1])])+[a[k]] )[~a[k]:]))