s=input() lens=len(s) if s[1:] == "3"*(lens-1) and lens>=2 and s[0]=="1": print(lens-1) else: print(-1)