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