from functools import lru_cache

x, y = input(), input()

def expand(string):
    res = 0
    out = ""
    for c in string:
        if c.isdigit():
            out += "_"*int(c)
            res += 1
        else:
            out += c
    return out, res

x, ex = expand(x)
y, ey = expand(y)
n, m = len(x)-1, len(y)-1

@lru_cache(maxsize=1_000_000)
def edit(i, j):
    if i > n: return m - j + 1
    if j > m: return n - i + 1

    lz = edit(i+1, j+1)
    if x[i] != y[j] and x[i] != "_" and y[j] != "_":
        lz += 2
    ls = edit(i+1, j)
    lv = edit(i, j+1)
    
    return min([lz, ls, lv])

print(edit(0,0) + ex + ey)

