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