p, q = 0, 1
for x in map(int, input()):
    p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
print(p) p, q = 0, 1 p 0 q 1 for x in map(int, input()):
    p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x) x map(int, input()) map int input() input p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x) p min(p + x, q + 10 - x) min p + x p x q + 10 - x q + 10 q 10 x q min(p + x + 1, q + 9 - x) min p + x + 1 p + x p x 1 q + 9 - x q + 9 q 9 x print(p) print p p, q = 0, 1 0 p q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x) min(p + x + 1, q + 9 - x) q p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x) min(p + x, q + 10 - x) p q = 0, 1 1 q
p, q = 0, 1
for x in map(int, input()):
    p, q = min(p + x, q + 10 - x), min(p + x + 1, q + 9 - x)
print(p)
