a=b=0
for n in map(int,'0'+input()):a,b=n+min(a,b),9-n+min(b,a+2)
print(min(a,b)) a=b=0 a 0 =b=0 b 0 for n in map(int,'0'+input()):a,b=n+min(a,b),9-n+min(b,a+2) n map(int,'0'+input()) map int '0'+input() '0' input() input print(min(a,b)) print min(a,b) min a b b=0 0 b a=b=0 0 a
a=b=0
for n in map(int,'0'+input()):a,b=n+min(a,b),9-n+min(b,a+2)
print(min(a,b))