
# This is the "memoizing" dictionary of all distinct calls.
# Each distinct call is made only once and stored here.

D = {}

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

 if i1 < 0 or i2 < 0: return 0          # base cases

 if (i1,i2) in D: return D[ (i1,i2) ]   # already done!
   
 if s1[i1] == s2[i2]:
     result = 1 + LCS(i1-1, i2-1)
 else:
     result =  max( LCS(i1-1, i2), LCS(i1, i2-1) )

 D[ (i1,i2) ] = result                  # memo-ize it!

 return result                          # before returning


if __name__ == "__main__":

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

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

 print result


 
