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