S = input() if S[0] != "1": print(-1) else: l = list(S[1:]) s = set(l) if len(s) == 1 and s[0] == "3": print(len(l)) else: print(-1)