if __name__ == "__main__":

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

 DP = [ [0]*(L2+2) for i1 in range(L1+2) ]

 for i1 in range(L1):
   for i2 in range(L2):
     if s1[i1] == s2[i2]: DP[i1][i2] = 1 + DP[i1-1][i2-1]
     else: DP[i1][i2] = max( DP[i1][i2-1], DP[i1-1][i2] )

 result = DP[L1-1][L2-1]

 #for row in DP:
 #  print row

 print result




