import System.Environment
import Data.List (sortBy)
import Data.Ord (comparing)

process :: ([String] -> [String]) -> String -> String
process g = unlines . g . lines

longestLines :: [String] -> [String]
longestLines (x:xs) = take (read x) $ reverse (sortBy (comparing length) xs)

main = do
    (f:_) <- getArgs
    contents <- readFile f
    putStr $ process longestLines contents
