n = input() if n[0] != "1" or n == "1": ans = -1 elif n[1:] == "3" * (len(n) - 1): ans = len(n) - 1 else: ans = -1 print(ans)