N = [int(c) for c in input()]
dp = 0,1
for n in N:
  a = min(dp[0]+n,dp[1]+10-n)
  b = min(dp[0]+n+1,dp[1]+10-(n+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 n in N:
  a = min(dp[0]+n,dp[1]+10-n)
  b = min(dp[0]+n+1,dp[1]+10-(n+1))
  dp = a,b n N a = min(dp[0]+n,dp[1]+10-n) a min(dp[0]+n,dp[1]+10-n) min dp[0]+n dp[0] dp 0 n dp[1]+10-n dp[1]+10 dp[1] dp 1 10 n b = min(dp[0]+n+1,dp[1]+10-(n+1)) b min(dp[0]+n+1,dp[1]+10-(n+1)) min dp[0]+n+1 dp[0]+n dp[0] dp 0 n 1 dp[1]+10-(n+1) dp[1]+10 dp[1] dp 1 10 n+1 n 1 dp = a,b dp dp = a,b a b print(dp[0]) print dp[0] dp 0 N = [int(c) for c in input()] [int(c) for c in input()] N dp = 0,1 dp = 0,1 dp a = min(dp[0]+n,dp[1]+10-n) min(dp[0]+n,dp[1]+10-n) a b = min(dp[0]+n+1,dp[1]+10-(n+1)) min(dp[0]+n+1,dp[1]+10-(n+1)) b dp = a,b dp = a,b dp
N = [int(c) for c in input()]
dp = 0,1
for n in N:
  a = min(dp[0]+n,dp[1]+10-n)
  b = min(dp[0]+n+1,dp[1]+10-(n+1))
  dp = a,b
print(dp[0])