$i = $<.read.split while !$i.empty? do h, n = $i.shift(2).map(&:to_i) n -= 1 cnt_less = 1 n.times do hi = $i.shift.to_i cnt_less += 1 if hi > h end ord = case cnt_less % 10 when 1 "st" when 2 "nd" when 3 "rd" else "th" end puts "#{cnt_less}#{ord}" end