n, k = io.read("*n", "*n") p = {} for i = 1, n do p[i] = io.read("*n") end local cand = 401 for ib = 401, 0, -1 do c = 0 for i = 1, n do if ib <= p[i] then c = c + 1 end end if c <= k then cand = ib else break end end z = 0 for i = 1, n do if cand <= p[i] then z = z + 1 end end print(z)