solve n m s t = last $ foldl f initial s where
  f acc c = 0 : f 0 (zip (t ++ " ") acc) where
    f p ta@((d, a):(_, b):_) = it : f it (tail ta) where
      it = if c == d then a+1 else max p b
    f _ _ = []
  initial = replicate (m+1) 0
 
 main = do
   s <- getLine
   t <- getLine
   print $ solve (length s) (length t) s t