s = input()[::-1]
size = len(s)
s += "4"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += bef
print(ans) s = input()[::-1] s input()[::-1] () input ::-1 -1 size = len(s) size len(s) len s s += "4" s "4" ans = 0 ans 0 bef = 0 bef 0 for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0 i range(size) range size v1 = int(s[i]) v1 int(s[i]) int s[i] s i v2 = int(s[i+1]) v2 int(s[i+1]) int s[i+1] s i+1 i 1 if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0 v1+bef>=6 or (v1+bef>=5 and v2>=5) v1+bef>=6 v1+bef v1 bef 6 v1+bef>=5 and v2>=5 v1+bef>=5 v1+bef v1 bef 5 v2>=5 v2 5 ans += 10-(v1+bef) ans 10-(v1+bef) 10 v1+bef v1 bef bef = 1 bef 1 ans += (v1+bef) ans v1+bef v1 bef bef = 0 bef 0 ans += bef ans bef print(ans) print ans ans += 10-(v1+bef) 10-(v1+bef) ans bef = 1 1 bef ans = 0 0 ans bef = 0 0 bef v2 = int(s[i+1]) int(s[i+1]) v2 size = len(s) len(s) size bef = 0 0 bef s = input()[::-1] input()[::-1] s v1 = int(s[i]) int(s[i]) v1 ans += bef bef ans s += "4" "4" s ans += (v1+bef) v1+bef ans
s = input()[::-1]
size = len(s)
s += "4"

ans = 0
bef = 0

for i in range(size):
    v1 = int(s[i])
    v2 = int(s[i+1])
    if v1+bef>=6 or (v1+bef>=5 and v2>=5):
        ans += 10-(v1+bef)
        bef = 1
    else:
        ans += (v1+bef)
        bef = 0

ans += bef
print(ans)