N=input() if N[0]!="1": print(-1) else: ANS=0 for n in N[1:]: if n=="3": ANS+=1 else: print(-1) break else: print(ANS)