# Daniel Kim
# Bergen County Academies
# Senior Division

import math

file_name = "2sr_sampledata.txt"

def find_substring(word1, word2):
    longest_length = 0
    longests = []
    for i in range(len(word1)):
        for j in range(i+1, len(word1)+1):
            if ((word1[i:j] in word2) and (len(word1[i:j]) >= longest_length)):
                if (len(word1[i:j]) > longest_length): longests = []
                longest_length = len(word1[i:j])
                longests.append(word1[i:j])
    longests.sort()
    if (len(longests) == 0): return 0
    best = longests[0]
    return longest_length + find_substring(word1.split(best, 1)[0], word2.split(best, 1)[0]) + find_substring(word1.split(best, 1)[1], word2.split(best, 1)[1])
    

def filter(word):
    word = word.strip().upper()
    new_word = []
    for c in word:
        if (c.isalpha()): new_word.append(c)
    return ''.join(new_word)

with open(file_name, "r") as test_cases:
    while True:
        line1 = filter(test_cases.readline())
        line2 = filter(test_cases.readline())
        if not line2: break
        print(find_substring(line1,line2))