N = input() if N[0] == "1": a = 1 else: a = 0 b = N.count("3") if a+b == len(N): print(b) else: print(-1)