//By: Luogu@rui_er(122461)
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, k = 1, i;
	cin>>n;
	int a[n];
	for(i=0;i<n;i++) cin>>a[i];
	for(i=0;i<n;i++)
	{
		k = a[k-1];
		if(k == 2) break;
	}
	if(k == 2) cout<<i+1<<endl;
	else cout<<-1<<endl;
	return 0;
}