import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Btn = new int[N + 1];
	}

	int[] Btn;

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		Btn[cnt] = Integer.parseInt(str);
	}

	public void solve() {
		// for (int i = 1; i <= N; i++)
		// System.out.println(Btn[i]);
		int ans = 0;
		for (int b = 1; b != 2 && ans < N; b = Btn[b]) {
			ans++;
		}
		if (ans < N)
			System.out.println(ans);
		else
			System.out.println(-1);
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
} Main public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} main {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	} BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); in new BufferedReader(new InputStreamReader(System.in)) Solver solver = new Solver(); solver new Solver() solver.init() solver.init solver solver.readHead(in.readLine()) solver.readHead solver in.readLine() in.readLine in for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		} ; solver.hasNext() solver.hasNext solver {
			solver.readBody(in.readLine());
		} {
			solver.readBody(in.readLine());
		} solver.readBody(in.readLine()) solver.readBody solver in.readLine() in.readLine in solver.solve() solver.solve solver String args[] args class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Btn = new int[N + 1];
	}

	int[] Btn;

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		Btn[cnt] = Integer.parseInt(str);
	}

	public void solve() {
		// for (int i = 1; i <= N; i++)
		// System.out.println(Btn[i]);
		int ans = 0;
		for (int b = 1; b != 2 && ans < N; b = Btn[b]) {
			ans++;
		}
		if (ans < N)
			System.out.println(ans);
		else
			System.out.println(-1);
	}
} Solver int N; N int cnt; cnt int[] Btn; Btn public void init() {
		N = 0;
		cnt = 0;
	} init {
		N = 0;
		cnt = 0;
	} N = 0 N 0 cnt = 0 cnt 0 public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Btn = new int[N + 1];
	} readHead {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Btn = new int[N + 1];
	} String[] strArr = str.split(" "); strArr str.split(" ") str.split str " " N = Integer.parseInt(strArr[0]) N Integer.parseInt(strArr[0]) Integer.parseInt Integer strArr[0] strArr 0 Btn = new int[N + 1] Btn new int[N + 1] N + 1 N 1 String str str public boolean hasNext() {
		return cnt < N;
	} hasNext {
		return cnt < N;
	} return cnt < N; cnt < N cnt N public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		Btn[cnt] = Integer.parseInt(str);
	} readBody {
		// System.out.println(str);
		cnt++;
		Btn[cnt] = Integer.parseInt(str);
	} cnt++ cnt Btn[cnt] = Integer.parseInt(str) Btn[cnt] Btn cnt Integer.parseInt(str) Integer.parseInt Integer str String str str public void solve() {
		// for (int i = 1; i <= N; i++)
		// System.out.println(Btn[i]);
		int ans = 0;
		for (int b = 1; b != 2 && ans < N; b = Btn[b]) {
			ans++;
		}
		if (ans < N)
			System.out.println(ans);
		else
			System.out.println(-1);
	} solve {
		// for (int i = 1; i <= N; i++)
		// System.out.println(Btn[i]);
		int ans = 0;
		for (int b = 1; b != 2 && ans < N; b = Btn[b]) {
			ans++;
		}
		if (ans < N)
			System.out.println(ans);
		else
			System.out.println(-1);
	} int ans = 0; ans 0 for (int b = 1; b != 2 && ans < N; b = Btn[b]) {
			ans++;
		} int b = 1; int b = 1; b 1 b != 2 && ans < N b != 2 b 2 ans < N ans N b = Btn[b] b = Btn[b] b Btn[b] Btn b {
			ans++;
		} {
			ans++;
		} ans++ ans if (ans < N)
			System.out.println(ans);
		else
			System.out.println(-1); ans < N ans N System.out.println(ans) System.out.println System.out System System.out ans System.out.println(-1) System.out.println System.out System System.out -1 1
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		Solver solver = new Solver();
		solver.init();
		solver.readHead(in.readLine());
		for (; solver.hasNext();) {
			solver.readBody(in.readLine());
		}
		solver.solve();
	}
}

class Solver {
	int N;
	int cnt;

	public void init() {
		N = 0;
		cnt = 0;
	}

	public void readHead(String str) {
		String[] strArr = str.split(" ");
		N = Integer.parseInt(strArr[0]);
		// System.out.println(N);
		Btn = new int[N + 1];
	}

	int[] Btn;

	public boolean hasNext() {
		return cnt < N;
	}

	public void readBody(String str) {
		// System.out.println(str);
		cnt++;
		Btn[cnt] = Integer.parseInt(str);
	}

	public void solve() {
		// for (int i = 1; i <= N; i++)
		// System.out.println(Btn[i]);
		int ans = 0;
		for (int b = 1; b != 2 && ans < N; b = Btn[b]) {
			ans++;
		}
		if (ans < N)
			System.out.println(ans);
		else
			System.out.println(-1);
	}
}
