s = input()
state = [0, 1]
for i in s:
    n = int(i)
    state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)]
    state = state_new
print(state[0]) s = input() s input() input state = [0, 1] state [0, 1] 0 1 for i in s:
    n = int(i)
    state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)]
    state = state_new i s n = int(i) n int(i) int i state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)] state_new [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)] min(state[0] + n, state[1] + 10 - n) min state[0] + n state[0] state 0 n state[1] + 10 - n state[1] + 10 state[1] state 1 10 n min(state[0] + n + 1, state[1] + 9 - n) min state[0] + n + 1 state[0] + n state[0] state 0 n 1 state[1] + 9 - n state[1] + 9 state[1] state 1 9 n state = state_new state state_new print(state[0]) print state[0] state 0 state = state_new state_new state s = input() input() s n = int(i) int(i) n state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)] [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)] state_new state = [0, 1] [0, 1] state
s = input()
state = [0, 1]
for i in s:
    n = int(i)
    state_new = [min(state[0] + n, state[1] + 10 - n), 
                 min(state[0] + n + 1, state[1] + 9 - n)]
    state = state_new
print(state[0])