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