#include<iostream>
#include<vector>
using namespace std;
int main()
{
	int n, a, ans=0;
	cin>>n;
	vector<int>v(n+1);
	for(int i=1;i<=n;++i)cin>>v[i];
	a = v[1];
	for(int i=0;i<n;++i){
		if(a == 2) {
			cout<<ans+1<<endl;
			break;
		}
		a = v[a];
	    ++ans;
	}
	if(a != 2) cout<<-1<<endl;
	return 0;
}
