def solve(): n = input() len_n = len(n) if n[0] == "1": return len_n - 1 if "1" + "3" * (len_n - 1) == n else -1 if n[0] == "3": return len_n if "3" * len_n == n else -1 return -1 print(solve())