import Control.Applicative ((<$>)) import Control.Monad import Data.List main :: IO () main = do [h, n] <- getl $ map read . words solve h <$> replicateM (n - 1) (getl read) >>= putStrLn solve :: Int -> [Int] -> String solve h hs = ordinal . (+1) . length . takeWhile (> h) . sortBy (flip compare) $ hs where ordinal x = case x `mod` 10 of 1 -> show x ++ "st" 2 -> show x ++ "nd" 3 -> show x ++ "rd" _ -> show x ++ "th" getl :: (String -> a) -> IO a getl f = f <$> getLine