import sys S=list(input()) c=len(S) if S==["1"]: print(-1) sys.exit() if S[0]=="1" and S.count("1")==1 and S.count("3")==c-1: print(c-1) else: print(-1)