N,K = map(int,input().split()) P = list(map(int,input().split())) ans = 0 for B in range(max(P)+2): count = 0 for p in P: if p >= B: count += 1 if count <= K: ans = max(ans,count) print(ans)