s=input();a=b=1;c=len(s) for i in s: if i in '0469':a+=1 elif'8'==i:a+=2 b=a*2;a+=c*2;b+=c;print(min(a,b))