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