n=input() def calc(x): if x in "12357": return 0 if x in "0469": return 1 return 2 ANS=len(n)*2+1 for x in n: ANS+=calc(x) #print(ANS) ANS2=len(n)+2 for x in n: ANS2+=calc(x)*2 print(min(ANS,ANS2))