import Control.Monad import Data.Char import Data.List f :: Char -> Int f c | isAlpha c = ord c - ord 'A' + 10 | otherwise = digitToInt c main = do n <- readLn as <- replicateM n $ do s <- getLine let l = ['0'..'9'] ++ ['a'..'z'] b = maximum $ map ((+1) . f) s g [] x = x g (c:s) x = g s (x * b + f c) in return $ g s 0 print $ minimum as