n=list(map(int,input()))
keta=len(n)
satsu=0

for i in range(keta):
    tmp = n.pop()
    if i == keta-1:
        n.append(0)
    
    if tmp == 10:
        tmp=0
        n[-1]=n[-1]+1
    if tmp > 5 or (tmp==5 and n[-1] >= 5):
        satsu += 10 - tmp
        n[-1] = n[-1] + 1
    else:
        satsu += tmp

print(satsu+n[0]) n=list(map(int,input())) n list(map(int,input())) list map(int,input()) map int input() input keta=len(n) keta len(n) len n satsu=0 satsu 0 for i in range(keta):
    tmp = n.pop()
    if i == keta-1:
        n.append(0)
    
    if tmp == 10:
        tmp=0
        n[-1]=n[-1]+1
    if tmp > 5 or (tmp==5 and n[-1] >= 5):
        satsu += 10 - tmp
        n[-1] = n[-1] + 1
    else:
        satsu += tmp i range(keta) range keta tmp = n.pop() tmp n.pop() n.pop n pop if i == keta-1:
        n.append(0)
    
     i == keta-1 i keta-1 keta 1 n.append(0) n.append n append 0 if tmp == 10:
        tmp=0
        n[-1]=n[-1]+1
     tmp == 10 tmp 10 tmp=0 tmp 0 n[-1]=n[-1]+1 n[-1] n -1 n[-1]+1 n[-1] n -1 1 if tmp > 5 or (tmp==5 and n[-1] >= 5):
        satsu += 10 - tmp
        n[-1] = n[-1] + 1
    else:
        satsu += tmp tmp > 5 or (tmp==5 and n[-1] >= 5) tmp > 5 tmp 5 tmp==5 and n[-1] >= 5 tmp==5 tmp 5 n[-1] >= 5 n[-1] n -1 5 satsu += 10 - tmp satsu 10 - tmp 10 tmp n[-1] = n[-1] + 1 n[-1] n -1 n[-1] + 1 n[-1] n -1 1 satsu += tmp satsu tmp print(satsu+n[0]) print satsu+n[0] satsu n[0] n 0 n=list(map(int,input())) list(map(int,input())) n tmp = n.pop() n.pop() tmp satsu=0 0 satsu keta=len(n) len(n) keta tmp=0 0 tmp satsu += tmp tmp satsu satsu += 10 - tmp 10 - tmp satsu
n=list(map(int,input()))
keta=len(n)
satsu=0

for i in range(keta):
    tmp = n.pop()
    if i == keta-1:
        n.append(0)
    
    if tmp == 10:
        tmp=0
        n[-1]=n[-1]+1
    if tmp > 5 or (tmp==5 and n[-1] >= 5):
        satsu += 10 - tmp
        n[-1] = n[-1] + 1
    else:
        satsu += tmp

print(satsu+n[0])
