kuri_now = False
cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]
kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1]
result = 0
for digit in reversed(input()):
    digit = int(digit)
    if kuri_now == 0:
        result += cost[digit]
        kuri_now = kuri[digit]
    elif kuri_now == 1:
        result += cost[digit + 1]
        kuri_now = kuri[digit + 1]
    else:
        if cost[digit] <= cost[digit + 1]:
            result += cost[digit]
            kuri_now = kuri[digit]
        else:
            result += cost[digit + 1]
            kuri_now = kuri[digit + 1]
if kuri_now == 1:
    result += 1
print(result) kuri_now = False kuri_now False cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] cost [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] 0 1 2 3 4 5 4 3 2 1 0 kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1] kuri [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1] 0 0 0 0 0 0.5 1 1 1 1 1 result = 0 result 0 for digit in reversed(input()):
    digit = int(digit)
    if kuri_now == 0:
        result += cost[digit]
        kuri_now = kuri[digit]
    elif kuri_now == 1:
        result += cost[digit + 1]
        kuri_now = kuri[digit + 1]
    else:
        if cost[digit] <= cost[digit + 1]:
            result += cost[digit]
            kuri_now = kuri[digit]
        else:
            result += cost[digit + 1]
            kuri_now = kuri[digit + 1] digit reversed(input()) reversed input() input digit = int(digit) digit int(digit) int digit if kuri_now == 0:
        result += cost[digit]
        kuri_now = kuri[digit]
    elif kuri_now == 1:
        result += cost[digit + 1]
        kuri_now = kuri[digit + 1]
    else:
        if cost[digit] <= cost[digit + 1]:
            result += cost[digit]
            kuri_now = kuri[digit]
        else:
            result += cost[digit + 1]
            kuri_now = kuri[digit + 1] kuri_now == 0 kuri_now 0 result += cost[digit] result cost[digit] cost digit kuri_now = kuri[digit] kuri_now kuri[digit] kuri digit elif kuri_now == 1:
        result += cost[digit + 1]
        kuri_now = kuri[digit + 1]
     kuri_now == 1 kuri_now 1 result += cost[digit + 1] result cost[digit + 1] cost digit + 1 digit 1 kuri_now = kuri[digit + 1] kuri_now kuri[digit + 1] kuri digit + 1 digit 1 if cost[digit] <= cost[digit + 1]:
            result += cost[digit]
            kuri_now = kuri[digit]
        else:
            result += cost[digit + 1]
            kuri_now = kuri[digit + 1] cost[digit] <= cost[digit + 1] cost[digit] cost digit cost[digit + 1] cost digit + 1 digit 1 result += cost[digit] result cost[digit] cost digit kuri_now = kuri[digit] kuri_now kuri[digit] kuri digit result += cost[digit + 1] result cost[digit + 1] cost digit + 1 digit 1 kuri_now = kuri[digit + 1] kuri_now kuri[digit + 1] kuri digit + 1 digit 1 if kuri_now == 1:
    result += 1 kuri_now == 1 kuri_now 1 result += 1 result 1 print(result) print result kuri_now = kuri[digit + 1] kuri[digit + 1] kuri_now result += 1 1 result kuri_now = kuri[digit + 1] kuri[digit + 1] kuri_now cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0] cost result = 0 0 result kuri_now = kuri[digit] kuri[digit] kuri_now digit = int(digit) int(digit) digit result += cost[digit + 1] cost[digit + 1] result result += cost[digit] cost[digit] result kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1] [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1] kuri result += cost[digit + 1] cost[digit + 1] result kuri_now = False False kuri_now result += cost[digit] cost[digit] result kuri_now = kuri[digit] kuri[digit] kuri_now
kuri_now = False
cost = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]
kuri = [0, 0, 0, 0, 0, 0.5, 1, 1, 1, 1, 1]
result = 0
for digit in reversed(input()):
    digit = int(digit)
    if kuri_now == 0:
        result += cost[digit]
        kuri_now = kuri[digit]
    elif kuri_now == 1:
        result += cost[digit + 1]
        kuri_now = kuri[digit + 1]
    else:
        if cost[digit] <= cost[digit + 1]:
            result += cost[digit]
            kuri_now = kuri[digit]
        else:
            result += cost[digit + 1]
            kuri_now = kuri[digit + 1]
if kuri_now == 1:
    result += 1
print(result)