N = input()
DP = [0,0]
kuriagari = 0
kuriagarazu = 0
for n in N:
    n = int(n)
    kuriagaru = 11 - n + kuriagari
    kuriagaranai = n + kuriagarazu
    DP.append([kuriagaru, kuriagaranai])
    kuriagari = DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1]
    kuriagarazu = DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1]

answer = min(DP[-1])
print(answer) N = input() N input() input DP = [0,0] DP [0,0] 0 0 kuriagari = 0 kuriagari 0 kuriagarazu = 0 kuriagarazu 0 for n in N:
    n = int(n)
    kuriagaru = 11 - n + kuriagari
    kuriagaranai = n + kuriagarazu
    DP.append([kuriagaru, kuriagaranai])
    kuriagari = DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1]
    kuriagarazu = DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1] n N n = int(n) n int(n) int n kuriagaru = 11 - n + kuriagari kuriagaru 11 - n + kuriagari 11 - n 11 n kuriagari kuriagaranai = n + kuriagarazu kuriagaranai n + kuriagarazu n kuriagarazu DP.append([kuriagaru, kuriagaranai]) DP.append DP append [kuriagaru, kuriagaranai] kuriagaru kuriagaranai kuriagari = DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1] kuriagari DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1] DP[-1][0] - 2 < DP[-1][1] DP[-1][0] - 2 DP[-1][0] [-1] DP -1 0 2 DP[-1][1] [-1] DP -1 1 DP[-1][0] - 2 DP[-1][0] [-1] DP -1 0 2 DP[-1][1] [-1] DP -1 1 kuriagarazu = DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1] kuriagarazu DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1] DP[-1][0] < DP[-1][1] DP[-1][0] [-1] DP -1 0 DP[-1][1] [-1] DP -1 1 DP[-1][0] [-1] DP -1 0 DP[-1][1] [-1] DP -1 1 answer = min(DP[-1]) answer min(DP[-1]) min DP[-1] DP -1 print(answer) print answer N = input() input() N answer = min(DP[-1]) min(DP[-1]) answer DP = [0,0] [0,0] DP kuriagari = 0 0 kuriagari kuriagari = DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1] DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1] kuriagari kuriagarazu = DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1] DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1] kuriagarazu kuriagaru = 11 - n + kuriagari 11 - n + kuriagari kuriagaru n = int(n) int(n) n kuriagaranai = n + kuriagarazu n + kuriagarazu kuriagaranai kuriagarazu = 0 0 kuriagarazu
N = input()
DP = [0,0]
kuriagari = 0
kuriagarazu = 0
for n in N:
    n = int(n)
    kuriagaru = 11 - n + kuriagari
    kuriagaranai = n + kuriagarazu
    DP.append([kuriagaru, kuriagaranai])
    kuriagari = DP[-1][0] - 2 if DP[-1][0] - 2 < DP[-1][1] else DP[-1][1]
    kuriagarazu = DP[-1][0] if DP[-1][0] < DP[-1][1] else DP[-1][1]

answer = min(DP[-1])
print(answer)