class memoize:

  def __init__(self, function):
    self.function = function
    self.memoized = {}

  def __call__(self, *args):
    try:
      return self.memoized[args]
    except KeyError:
      self.memoized[args] = self.function(*args)
      return self.memoized[args]


@memoize
def LCS( i1, i2 ):
 """ classic LCS """

 if i1 < 0 or i2 < 0: return 0

 if s1[i1] == s2[i2]:
     return 1 + LCS(i1 - 1, i2 - 1)
 else:
     return max(LCS(i1 - 1, i2), LCS(i1, i2 - 1))



if __name__ == "__main__":

 s1 = raw_input(); L1 = len(s1)
 s2 = raw_input(); L2 = len(s2)

 result = LCS( L1-1, L2-1 )

 print result
