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