n = list(map(int, input()))
dp = (0, 1)
for i in n:
  dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i))
print(dp[0]) n = list(map(int, input())) n list(map(int, input())) list map(int, input()) map int input() input dp = (0, 1) dp (0, 1) 0 1 for i in n:
  dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i)) i n dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i)) dp (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i)) min(dp[0] + i, dp[1] + 10 - i) min dp[0] + i dp[0] dp 0 i dp[1] + 10 - i dp[1] + 10 dp[1] dp 1 10 i min(dp[0] + i + 1, dp[1] + 9 - i) min dp[0] + i + 1 dp[0] + i dp[0] dp 0 i 1 dp[1] + 9 - i dp[1] + 9 dp[1] dp 1 9 i print(dp[0]) print dp[0] dp 0 n = list(map(int, input())) list(map(int, input())) n dp = (0, 1) (0, 1) dp dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i)) (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i)) dp
n = list(map(int, input()))
dp = (0, 1)
for i in n:
  dp = (min(dp[0] + i, dp[1] + 10 - i), min(dp[0] + i + 1, dp[1] + 9 - i))
print(dp[0])