main = do
 s <- getLine
 t <- getLine
 putStrLn $ solve s t
 
 solve :: String -> String -> String
 solve [] _  = []
 solve _  [] = []
 solve xxs@(x:xs) yys@(y:ys) 
  | x == y = x : solve xs ys
  | otherwise = maxBy length (solve xxs ys) (solve xs yys)