S = map(int, input())

a, b = 0, 1
for s in S:
    a, b = min(a + s, b + 10 - s), min(a + (s + 1), b + 10 - (s + 1))

print(a) S = map(int, input()) S map(int, input()) map int input() input a, b = 0, 1 a 0 b 1 for s in S:
    a, b = min(a + s, b + 10 - s), min(a + (s + 1), b + 10 - (s + 1)) s S a, b = min(a + s, b + 10 - s), min(a + (s + 1), b + 10 - (s + 1)) a min(a + s, b + 10 - s) min a + s a s b + 10 - s b + 10 b 10 s b min(a + (s + 1), b + 10 - (s + 1)) min a + (s + 1) a s + 1 s 1 b + 10 - (s + 1) b + 10 b 10 s + 1 s 1 print(a) print a a, b = min(a + s, b + 10 - s), min(a + (s + 1), b + 10 - (s + 1)) min(a + s, b + 10 - s) a b = min(a + s, b + 10 - s), min(a + (s + 1), b + 10 - (s + 1)) min(a + (s + 1), b + 10 - (s + 1)) b S = map(int, input()) map(int, input()) S a, b = 0, 1 0 a b = 0, 1 1 b
S = map(int, input())

a, b = 0, 1
for s in S:
    a, b = min(a + s, b + 10 - s), min(a + (s + 1), b + 10 - (s + 1))

print(a)