#include<iostream>
using namespace std;
int mark[100001],a[100005];
int main()
{
	int n,x,c=0;
	cin>>n;
	for(int i=1;i<=n;i++)
	cin>>a[i];
	x=1;
	c=0;
	mark[1]=1; 
	while(x!=2)
	{
		c++;
		x=a[x];
		if(mark[x])
		break;
		mark[x]=1;
	}
	if(x==2)
	cout<<c;
	else
	cout<<-1;
	return 0;
}
