n=input() if len(n)-1==n.count("3"): print(n.count("3")) elif n=="1" or n=="2":print(-1) elif n[-1]=="1":print(-1) else: print(-1)