import sys input=lambda: sys.stdin.readline().rstrip() N=input() hole=0 for n in N: if int(n) in [0,4,6,9]: hole+=1 elif n=="8": hole+=2 let=len(N) print(min(let+2*hole+2,2*let+1+hole))