n = input()
a, b = 0, 100
for i in n:
  j = int(i)
  a, b = min(a+j,b+j), min(a+11-j,b+9-j)
  if j == 0:
    b = a+100
print(min(a,b)) n = input() n input() input a, b = 0, 100 a 0 b 100 for i in n:
  j = int(i)
  a, b = min(a+j,b+j), min(a+11-j,b+9-j)
  if j == 0:
    b = a+100 i n j = int(i) j int(i) int i a, b = min(a+j,b+j), min(a+11-j,b+9-j) a min(a+j,b+j) min a+j a j b+j b j b min(a+11-j,b+9-j) min a+11-j a+11 a 11 j b+9-j b+9 b 9 j if j == 0:
    b = a+100 j == 0 j 0 b = a+100 b a+100 a 100 print(min(a,b)) print min(a,b) min a b a, b = 0, 100 0 a n = input() input() n b = a+100 a+100 b j = int(i) int(i) j b = 0, 100 100 b a, b = min(a+j,b+j), min(a+11-j,b+9-j) min(a+j,b+j) a b = min(a+j,b+j), min(a+11-j,b+9-j) min(a+11-j,b+9-j) b
n = input()
a, b = 0, 100
for i in n:
  j = int(i)
  a, b = min(a+j,b+j), min(a+11-j,b+9-j)
  if j == 0:
    b = a+100
print(min(a,b))