n,k=map(int,input().split()) L=list(map(int,input().split())) a=0 for b in range(max(L),-1,-1): c=L.count(b) if a+c>k:break else: a+=c print(a)