class Problem0791: def solve(this): n = input() res = -1 cnt = n.count("3") if len(n) == cnt + 1 and n[0] == "1" and cnt != 0: res = cnt print(res) if __name__ == "__main__": problem = Problem0791() problem.solve()