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