import Control.Monad
import Data.Array
import Data.Array.Unboxed as UA
import Data.Array.ST
import Control.Monad.ST
import qualified Data.ByteString.Char8 as B

main=B.interact $ B.pack.f.take 2.B.lines

f [s,t]=mk "" (ls-1) (lt-1) where
    ls = B.length s
    lt = B.length t
    mk as si ti
        | si<0 || ti<0 = as
        | B.index s si == B.index t ti = mk (B.index s si:as) (si-1) (ti-1)
        | aa  UA.! (si+1,ti)>aa UA.! (si,ti+1) = mk as si (ti-1)
        | otherwise = mk as (si-1) ti
    aa :: UA.UArray (Int,Int) Int
    aa = runST $ do
        dp <- newArray ((0,0),(ls,lt)) 0 :: ST s (STUArray s (Int,Int) Int)
        forM_ [(i,j)|i<-[1..ls], j<-[1..lt]] $ \(i,j)->
            if B.index s (i-1) == B.index t (j-1)
                then writeArray dp (i,j) =<< (+1) <$> readArray dp (i-1,j-1)
                else writeArray dp (i,j) =<< max <$> readArray dp (i-1,j) <*> readArray dp (i,j-1)
        freeze dp