(defn input []
  (->> (repeatedly (Integer/parseInt (read-line)) read-line)
    (mapv #(Integer/parseInt %))))

(defn Trained? [A]
  (loop [i (A 0) n 1]
    (case i
      1 -1
      2 n
      (recur (A (dec i)) (inc n)))))

(-> (input)
  Trained?
  println)