import Data.List (maximumBy)
import Data.Function (on)
import Data.Ord (compare)

main :: IO ()
main = do
 s <- getLine
 t <- getLine
 putStrLn $ solve s t
 
solve :: Eq a => [a] -> [a] -> [a]
solve [] _  = []
solve _  [] = []
solve xxs@(x:xs) yys@(y:ys)
 | x == y = x : solve xs ys
 | otherwise = maximumBy (compare `on` length) [solve xxs ys, solve xs yys]

