#!/usr/bin python3
# -*- coding: utf-8 -*-

N = list(map(int, list(input())))
N.reverse()
N=N+[0]
cnt = 0
for i in range(len(N)):
    n=N[i]
    if n<5:
        cnt+=n
    elif n==5:
        cnt+=n
        if N[i+1]>=5:
            N[i+1]+=1
    else:
        cnt+=10-n
        N[i+1]+=1
print(cnt) N = list(map(int, list(input()))) N list(map(int, list(input()))) list map(int, list(input())) map int list(input()) list input() input N.reverse() N.reverse N reverse N=N+[0] N N+[0] N [0] 0 cnt = 0 cnt 0 for i in range(len(N)):
    n=N[i]
    if n<5:
        cnt+=n
    elif n==5:
        cnt+=n
        if N[i+1]>=5:
            N[i+1]+=1
    else:
        cnt+=10-n
        N[i+1]+=1 i range(len(N)) range len(N) len N n=N[i] n N[i] N i if n<5:
        cnt+=n
    elif n==5:
        cnt+=n
        if N[i+1]>=5:
            N[i+1]+=1
    else:
        cnt+=10-n
        N[i+1]+=1 n<5 n 5 cnt+=n cnt n elif n==5:
        cnt+=n
        if N[i+1]>=5:
            N[i+1]+=1
     n==5 n 5 cnt+=n cnt n if N[i+1]>=5:
            N[i+1]+=1
     N[i+1]>=5 N[i+1] N i+1 i 1 5 N[i+1]+=1 N[i+1] N i+1 i 1 1 cnt+=10-n cnt 10-n 10 n N[i+1]+=1 N[i+1] N i+1 i 1 1 print(cnt) print cnt cnt = 0 0 cnt cnt+=10-n 10-n cnt N=N+[0] N+[0] N n=N[i] N[i] n N = list(map(int, list(input()))) list(map(int, list(input()))) N cnt+=n n cnt cnt+=n n cnt
#!/usr/bin python3
# -*- coding: utf-8 -*-

N = list(map(int, list(input())))
N.reverse()
N=N+[0]
cnt = 0
for i in range(len(N)):
    n=N[i]
    if n<5:
        cnt+=n
    elif n==5:
        cnt+=n
        if N[i+1]>=5:
            N[i+1]+=1
    else:
        cnt+=10-n
        N[i+1]+=1
print(cnt)
