(defn repeat-read [n]
  (for [i (range n)] (read)))

(defn create-data [n]
  (->>  (repeat-read n)
        (int-array)))

(defn finder [i arr countor n]
    (cond
      (= i 2) countor
      (= n countor) -1
      :else (recur (aget arr (- i 1)) arr (inc countor) n)))

(defn trained [arr]
  (finder 1 arr 0 (alength arr)))