#include <bits/stdc++.h>
using namespace std;

int main() {
	int n, a = 1, b = -1, c = 0;
	cin >> n;
	vector<int> vec(n);
	for(int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	while(c < n) {
        c++;
		a = vec.at(a - 1);
		if(a == 2) {
			b = c;
			break;
		}
	}
	cout << b << endl;
}