import Data.List

loop :: Int -> [String] -> IO ()
loop i l
  | i == 0 = print $ (sort [read $ a ++ b :: Int | a <- take 5 $ sort l, b <- take $ sort l, a /= b]) !! 2
  | otherwise = do
    n <- getLine
    loop (i-1) (n:l)

main :: IO ()
main = do
  i <- readLn
  loop i []
