import sys def main(): j = sys.stdin.read() if j[0] != "1": sys.stdout.write(str(-1) + "\n") return n = 0 for v in j[1:]: if v == "3": n += 1 elif v != "3": sys.stdout.write(str(-1) + "\n") return sys.stdout.write(str(n) + "\n")