import Control.Applicative import Data.List import Data.Ord import Data.Char sieve' = 2:3:[x|i<-[1..],j<-[-1,1], let x = 6*i+j, isPrime x] where isPrime n = null [p|p<-takeWhile (\x -> x*x <=n) sieve', rem n p == 0] solve :: [Int] -> Int solve ns = fst $ head $ iter' $ zip ns $ fmap hash ns where hash x = let x' = sum . fmap digitToInt . show $ x in if length (show x') == 1 then x' else hash x' iter' xs = maximumBy (comparing (\xs -> (length xs, fst $ head xs))) [flip iter [] $ drop p xs|p<-[0..length xs]] iter [] acc = acc iter (x:xs) acc = if snd x `elem` fmap snd acc then acc else iter xs (x:acc) main = do k <- (read :: String -> Int) <$> getLine n <- (read :: String -> Int) <$> getLine print $ solve $ reverse $ dropWhile (