n = list(input()) if set(n) != set(["1","3"]) or n[0] != "1": print(-1) else: print(n.count("3"))