s = str(input())
n = len(s)
dp = [[0]*2 for _ in range(n+1)]
dp[0][1] = 1
for i in range(n):
    p = int(s[i])
    dp[i+1][0] = min(dp[i][1]+10-p,dp[i][0]+p)
    dp[i+1][1] = min(dp[i][1]+10-p-1,dp[i][0]+p+1)
print(dp[-1][0]) s = str(input()) s str(input()) str input() input n = len(s) n len(s) len s [0]*2 for _ in range(n+1) for _ in range(n+1) _ range(n+1) range n+1 n 1 for _ in range(n+1) [0]*2 [0] 0 2 dp = [[0]*2 for _ in range(n+1)] dp [[0]*2 for _ in range(n+1)] dp[0][1] = 1 dp[0][1] [0] dp 0 1 1 for i in range(n):
    p = int(s[i])
    dp[i+1][0] = min(dp[i][1]+10-p,dp[i][0]+p)
    dp[i+1][1] = min(dp[i][1]+10-p-1,dp[i][0]+p+1) i range(n) range n p = int(s[i]) p int(s[i]) int s[i] s i dp[i+1][0] = min(dp[i][1]+10-p,dp[i][0]+p) dp[i+1][0] [i+1] dp i+1 i 1 0 min(dp[i][1]+10-p,dp[i][0]+p) min dp[i][1]+10-p dp[i][1]+10 dp[i][1] [i] dp i 1 10 p dp[i][0]+p dp[i][0] [i] dp i 0 p dp[i+1][1] = min(dp[i][1]+10-p-1,dp[i][0]+p+1) dp[i+1][1] [i+1] dp i+1 i 1 1 min(dp[i][1]+10-p-1,dp[i][0]+p+1) min dp[i][1]+10-p-1 dp[i][1]+10-p dp[i][1]+10 dp[i][1] [i] dp i 1 10 p 1 dp[i][0]+p+1 dp[i][0]+p dp[i][0] [i] dp i 0 p 1 print(dp[-1][0]) print dp[-1][0] [-1] dp -1 0 p = int(s[i]) int(s[i]) p s = str(input()) str(input()) s n = len(s) len(s) n dp = [[0]*2 for _ in range(n+1)] [[0]*2 for _ in range(n+1)] dp
s = str(input())
n = len(s)
dp = [[0]*2 for _ in range(n+1)]
dp[0][1] = 1
for i in range(n):
    p = int(s[i])
    dp[i+1][0] = min(dp[i][1]+10-p,dp[i][0]+p)
    dp[i+1][1] = min(dp[i][1]+10-p-1,dp[i][0]+p+1)
print(dp[-1][0])