Prof. Vasechkin wants to represent positive integer *n* as a sum of addends, where each addends is an integer number containing only 1s. For example, he can represent 121 as 121=111+11+–1. Help him to find the least number of digits 1 in such sum.
The first line of the input contains integer *n* (1 ≤ *n* &lt; 10<sup class="upper-index">15</sup>).
from sys import stdin, setrecursionlimit, stdout
#setrecursionlimit(1000000) #use "python" instead of "pypy" to avoid MLE
from collections import deque
from math import sqrt, floor, ceil, log, log2, log10, pi, gcd, sin, cos, asin
from heapq import heapify, heappop, heappush, heapreplace, heappushpop
from bisect import bisect_right, bisect_left
def ii(): return int(stdin.readline())
def fi(): return float(stdin.readline())
def mi(): return map(int, stdin.readline().split())
def fmi(): return map(float, stdin.readline().split())
def li(): return list(mi())
def si(): return stdin.readline().rstrip()
def lsi(): return list(si())
mod=1000000007
res=['NO', 'YES']


#######################################################################################
###########################    M Y     F U N C T I O N S    ###########################
#######################################################################################

def ones(n):
    global cnt
    x=0
    while True:
        p=x*10+1
        if abs(n-x)>abs(n-p):
            x=p
            cnt+=1
        else:
            return x

#######################################################################################
###########################    M A I N     P R O G R A M    ###########################
#######################################################################################


test=1
test_case=1
while test<=test_case:
    test+=1



    x=ii()
    cnt=0
    while x:
        x=abs(x-ones(x))
    print(cnt)