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