from itertools import repeat

def common_child(s1, s2):
    m = [[0] * (len(s2) + 1) for _ in repeat(None, len(s1) + 1)]

    for i, x in enumerate(s1, 1):
        for j, y in enumerate(s2, 1):
            m[i][j] = m[i - 1][j - 1] + 1 if x == y else max(m[i][j - 1], m[i - 1][j])

    return m[-1][-1]

print(common_child(input(), input()))

from itertools import repeat

def common_child(s1, s2):
    m = [[0] * (len(s2) + 1) for _ in repeat(None, len(s1) + 1)]

    for i, x in enumerate(s1, 1):
        for j, y in enumerate(s2, 1):
            m[i][j] = m[i - 1][j - 1] + 1 if x == y else max(m[i][j - 1], m[i - 1][j])

    return m[-1][-1]

print(common_child(input(), input()))
