n = "0" + input() # 文字列として受け取り
N = len(n)
plus = 1
just = 0
for i in range(1,N):
    #前の桁がplusだった場合の最低枚数を計算する
    plus_plus = plus+10-(int(n[i])+1)#この桁も１枚多く払う
    plus_just = plus+10-int(n[i])#この桁はちょうど払う
    #前の桁はちょうど払っていた場合
    just_plus = just+1+int(n[i])#この桁は１枚多く払う
    just_just = just+int(n[i])#この桁もちょうど払う
    
    plus = min(plus_plus,just_plus)
    just = min(just_just,plus_just)

#最後の桁は1枚余分に払う必要がない
print(just) n = "0" + input() n "0" + input() "0" input() input N = len(n) N len(n) len n plus = 1 plus 1 just = 0 just 0 for i in range(1,N):
    #前の桁がplusだった場合の最低枚数を計算する
    plus_plus = plus+10-(int(n[i])+1)#この桁も１枚多く払う
    plus_just = plus+10-int(n[i])#この桁はちょうど払う
    #前の桁はちょうど払っていた場合
    just_plus = just+1+int(n[i])#この桁は１枚多く払う
    just_just = just+int(n[i])#この桁もちょうど払う
    
    plus = min(plus_plus,just_plus)
    just = min(just_just,plus_just)

#最後の桁は1枚余分に払う必要がない i range(1,N) range 1 N plus_plus = plus+10-(int(n[i])+1) plus_plus plus+10-(int(n[i])+1) plus+10 plus 10 int(n[i])+1 int(n[i]) int n[i] n i 1 plus_just = plus+10-int(n[i]) plus_just plus+10-int(n[i]) plus+10 plus 10 int(n[i]) int n[i] n i just_plus = just+1+int(n[i]) just_plus just+1+int(n[i]) just+1 just 1 int(n[i]) int n[i] n i just_just = just+int(n[i]) just_just just+int(n[i]) just int(n[i]) int n[i] n i plus = min(plus_plus,just_plus) plus min(plus_plus,just_plus) min plus_plus just_plus just = min(just_just,plus_just) just min(just_just,plus_just) min just_just plus_just print(just) print just N = len(n) len(n) N plus_plus = plus+10-(int(n[i])+1) plus+10-(int(n[i])+1) plus_plus plus_just = plus+10-int(n[i]) plus+10-int(n[i]) plus_just just_just = just+int(n[i]) just+int(n[i]) just_just plus = 1 1 plus just = 0 0 just n = "0" + input() "0" + input() n plus = min(plus_plus,just_plus) min(plus_plus,just_plus) plus just_plus = just+1+int(n[i]) just+1+int(n[i]) just_plus just = min(just_just,plus_just) min(just_just,plus_just) just
n = "0" + input() # 文字列として受け取り
N = len(n)
plus = 1
just = 0
for i in range(1,N):
    #前の桁がplusだった場合の最低枚数を計算する
    plus_plus = plus+10-(int(n[i])+1)#この桁も１枚多く払う
    plus_just = plus+10-int(n[i])#この桁はちょうど払う
    #前の桁はちょうど払っていた場合
    just_plus = just+1+int(n[i])#この桁は１枚多く払う
    just_just = just+int(n[i])#この桁もちょうど払う
    
    plus = min(plus_plus,just_plus)
    just = min(just_just,plus_just)

#最後の桁は1枚余分に払う必要がない
print(just)