n = list(map(int, list(input())))
count = 0
n = n[::-1] + [0]

for idx, num in enumerate(n):
    if num == 10:
        n[idx+1] += 1
    elif num == 5:
        if n[idx+1] >= 5:
            n[idx+1] += 1
            count += 10 - num
        else:
            count += num

    elif num <= 4:
        count += num
    else:
        count += 10 - num
        n[idx+1] += 1

print(count) n = list(map(int, list(input()))) n list(map(int, list(input()))) list map(int, list(input())) map int list(input()) list input() input count = 0 count 0 n = n[::-1] + [0] n n[::-1] + [0] n[::-1] n ::-1 -1 [0] 0 for idx, num in enumerate(n):
    if num == 10:
        n[idx+1] += 1
    elif num == 5:
        if n[idx+1] >= 5:
            n[idx+1] += 1
            count += 10 - num
        else:
            count += num

    elif num <= 4:
        count += num
    else:
        count += 10 - num
        n[idx+1] += 1 idx num enumerate(n) enumerate n if num == 10:
        n[idx+1] += 1
    elif num == 5:
        if n[idx+1] >= 5:
            n[idx+1] += 1
            count += 10 - num
        else:
            count += num

    elif num <= 4:
        count += num
    else:
        count += 10 - num
        n[idx+1] += 1 num == 10 num 10 n[idx+1] += 1 n[idx+1] n idx+1 idx 1 1 elif num == 5:
        if n[idx+1] >= 5:
            n[idx+1] += 1
            count += 10 - num
        else:
            count += num

     num == 5 num 5 if n[idx+1] >= 5:
            n[idx+1] += 1
            count += 10 - num
        else:
            count += num

     n[idx+1] >= 5 n[idx+1] n idx+1 idx 1 5 n[idx+1] += 1 n[idx+1] n idx+1 idx 1 1 count += 10 - num count 10 - num 10 num count += num count num elif num <= 4:
        count += num
     num <= 4 num 4 count += num count num count += 10 - num count 10 - num 10 num n[idx+1] += 1 n[idx+1] n idx+1 idx 1 1 print(count) print count count += 10 - num 10 - num count count += num num count count = 0 0 count count += num num count n = list(map(int, list(input()))) list(map(int, list(input()))) n n = n[::-1] + [0] n[::-1] + [0] n count += 10 - num 10 - num count
n = list(map(int, list(input())))
count = 0
n = n[::-1] + [0]

for idx, num in enumerate(n):
    if num == 10:
        n[idx+1] += 1
    elif num == 5:
        if n[idx+1] >= 5:
            n[idx+1] += 1
            count += 10 - num
        else:
            count += num

    elif num <= 4:
        count += num
    else:
        count += 10 - num
        n[idx+1] += 1

print(count)