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