import collections as c n,k = map(int,input().split()) p = list(map(int,input().split())) ans = 0 for i in reversed(range(0,max(p))): b = i cnt = 0 for j in range(n): if p[j]>=b: cnt += 1 if cnt<=k: ans = max(ans,cnt) else: break print(ans)