n = [int(i) for i in list(input())]
a, b = 0, 1
for i in n:
    a, b = min(a+i, b+10-i), min(a+(i+1), b+10-(i+1))
print(a) int(i) for i in list(input()) for i in list(input()) i list(input()) list input() input for i in list(input()) int(i) int i n = [int(i) for i in list(input())] n [int(i) for i in list(input())] a, b = 0, 1 a 0 b 1 for i in n:
    a, b = min(a+i, b+10-i), min(a+(i+1), b+10-(i+1)) i n a, b = min(a+i, b+10-i), min(a+(i+1), b+10-(i+1)) a min(a+i, b+10-i) min a+i a i b+10-i b+10 b 10 i b min(a+(i+1), b+10-(i+1)) min a+(i+1) a i+1 i 1 b+10-(i+1) b+10 b 10 i+1 i 1 print(a) print a n = [int(i) for i in list(input())] [int(i) for i in list(input())] n b = min(a+i, b+10-i), min(a+(i+1), b+10-(i+1)) min(a+(i+1), b+10-(i+1)) b b = 0, 1 1 b a, b = min(a+i, b+10-i), min(a+(i+1), b+10-(i+1)) min(a+i, b+10-i) a a, b = 0, 1 0 a
n = [int(i) for i in list(input())]
a, b = 0, 1
for i in n:
    a, b = min(a+i, b+10-i), min(a+(i+1), b+10-(i+1))
print(a)
