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