import Control.Monad
import Data.List
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV

import Data.Array
import Data.Array.ST
import Control.Monad.ST

main=interact $ f.take 2.lines

f [s,t]=runST $ do
    dp <- newArray ((0,0),(ls,lt)) (0,"") :: ST s (STArray s (Int,Int) (Int,String))
    forM_ [(i,j,si,tj)|(i,si)<-zip [1..ls] s, (j,tj)<-zip [1..lt] t] $ \(i,j,si,tj)->
        if si == tj
            then writeArray dp (i,j) =<< (inc si) <$> readArray dp (i-1,j-1)
            else writeArray dp (i,j) =<< cp <$> readArray dp (i-1,j) <*> readArray dp (i,j-1)
    reverse.snd <$> readArray dp (ls,lt)
        where
        ls = length s
        lt = length t
        inc c (n,s) = (n+1, c:s)
        cp (a,sa) (b,sb) | a>b = (a,sa) | a<=b = (b,sb)