n=list(input()) count=0 for i in range(len(n)): if n[i]=="8": count+=2 elif n[i]=="0": count+=1 elif n[i]=="4": count+=1 elif n[i]=="6": count+=1 elif n[i]=="9": count+=1 else: count+=0 ans=2*len(n)+count+1 anv=2*(count+1)+len(n) print(min(ans,anv))