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