def main():
    S = map(int, input())

    a, b = 0, 1
    for s in S:
        a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

    print(a)


main() def main():
    S = map(int, input())

    a, b = 0, 1
    for s in S:
        a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

    print(a) main S = map(int, input()) S map(int, input()) map int input() input a, b = 0, 1 a 0 b 1 for s in S:
        a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

     s S a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) a a + s if a + s < b + 10 - s else b + 10 - s a + s < b + 10 - s a + s a s b + 10 - s b + 10 b 10 s a + s a s b + 10 - s b + 10 b 10 s b a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1) a + (s + 1) < b + 10 - (s + 1) a + (s + 1) a s + 1 s 1 b + 10 - (s + 1) b + 10 b 10 s + 1 s 1 a + (s + 1) a s + 1 s 1 b + 10 - (s + 1) b + 10 b 10 s + 1 s 1 print(a) print a main() main def main():
    S = map(int, input())

    a, b = 0, 1
    for s in S:
        a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

    print(a) def main():
    S = map(int, input())

    a, b = 0, 1
    for s in S:
        a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

    print(a) main
def main():
    S = map(int, input())

    a, b = 0, 1
    for s in S:
        a, b = a + s if a + s < b + 10 - s else b + 10 - s, a + (s + 1) if a + (s + 1) < b + 10 - (s + 1) else b + 10 - (s + 1)

    print(a)


main()