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