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