#include<iostream>
using namespace std;

int a[114514];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)cin >> a[i];
	int now = 0;
	for (int i = 0; i < 200000; i++) {
		now = a[now]-1;
		if (now == 1) {
			cout << i + 1 << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}