def main(): j = input() if j[0] != "1": print(-1) return n = 0 if (len(j[1:]) == 0) : print(-1) return for v in j[1:]: if v == "3": n += 1 elif v != "3": print(-1) return print(n) main()