box,toru=map(int,input().split()) ls=[int(i) for i in input().split()] ls.sort() flg=0 while True: for i in range(len(ls)): if ls[i]!=0: ls[i]-=1 toru-=1 if toru==0: flg=1 break if flg==1: break print(ls.count(0))