S=input() c=len(S) if S.count("1")==1 and S.count("3")==c-1: print(c-1) else: print(-1)