N = input() b = 1 for n in N: if n == '0' or n == '4' or n == '6' or n == '9': b += 1 elif n == '8': b += 2 print(min(2*len(N) + b, 2*b + len(N)))