N = [int(c) for c in input()]
dp = 0,1
for i in range(len(N)):
  a = min(dp[0]+N[i], dp[1]+10-N[i])
  b = min(dp[0]+N[i]+1, dp[1]+10-N[i]-1)
  dp = a,b
print(dp[0]) int(c) for c in input() for c in input() c input() input for c in input() int(c) int c N = [int(c) for c in input()] N [int(c) for c in input()] dp = 0,1 dp dp = 0,1 0 1 for i in range(len(N)):
  a = min(dp[0]+N[i], dp[1]+10-N[i])
  b = min(dp[0]+N[i]+1, dp[1]+10-N[i]-1)
  dp = a,b i range(len(N)) range len(N) len N a = min(dp[0]+N[i], dp[1]+10-N[i]) a min(dp[0]+N[i], dp[1]+10-N[i]) min dp[0]+N[i] dp[0] dp 0 N[i] N i dp[1]+10-N[i] dp[1]+10 dp[1] dp 1 10 N[i] N i b = min(dp[0]+N[i]+1, dp[1]+10-N[i]-1) b min(dp[0]+N[i]+1, dp[1]+10-N[i]-1) min dp[0]+N[i]+1 dp[0]+N[i] dp[0] dp 0 N[i] N i 1 dp[1]+10-N[i]-1 dp[1]+10-N[i] dp[1]+10 dp[1] dp 1 10 N[i] N i 1 dp = a,b dp dp = a,b a b print(dp[0]) print dp[0] dp 0 dp = a,b dp = a,b dp a = min(dp[0]+N[i], dp[1]+10-N[i]) min(dp[0]+N[i], dp[1]+10-N[i]) a N = [int(c) for c in input()] [int(c) for c in input()] N dp = 0,1 dp = 0,1 dp b = min(dp[0]+N[i]+1, dp[1]+10-N[i]-1) min(dp[0]+N[i]+1, dp[1]+10-N[i]-1) b
N = [int(c) for c in input()]
dp = 0,1
for i in range(len(N)):
  a = min(dp[0]+N[i], dp[1]+10-N[i])
  b = min(dp[0]+N[i]+1, dp[1]+10-N[i]-1)
  dp = a,b
print(dp[0])
