// Slower C++ solution:
#include <bits/stdc++.h>

using namespace std;



typedef long long   signed int LL;

typedef long long unsigned int LU;



#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)

#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)

#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)

#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)

#define  inc(i, n) incID(i, 0, n)

#define inc1(i, n) incII(i, 1, n)

#define  dec(i, n) decID(i, 0, n)

#define dec1(i, n) decII(i, 1, n)



#define inII(v, l, r) ((l) <= (v) && (v) <= (r))

#define inID(v, l, r) ((l) <= (v) && (v) <  (r))



#define PB push_back

#define EB emplace_back

#define MP make_pair

#define FI first

#define SE second

#define UB upper_bound

#define LB lower_bound

#define PQ priority_queue



#define  ALL(v)  v.begin(),  v.end()

#define RALL(v) v.rbegin(), v.rend()

#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)

#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)



template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }

template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }

template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }

template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }

template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }

template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }



// ---- ----



int n;

vector<pair<int, int>> v[100000];

int d[100000];



template<typename T> class RPQ : public PQ<T, vector<T>, greater<T>> { };

template<typename Cost> void dijkstra(int start, vector<pair<int, Cost>> g[], Cost dist[]) {

	RPQ<pair<Cost, int>> q;

	dist[start] = 0;

	q.emplace(dist[start], start);

	while(! q.empty()) {

		auto cp = q.top(); q.pop();

		int  p = cp.SE;

		Cost c = cp.FI;

		if(dist[p] != c) { continue; }

		for(auto && e : g[p]) {

			int  ep = e.FI;

			Cost ec = e.SE;

			if(setmin(dist[ep], dist[p] + ec)) { q.emplace(dist[ep], ep); }

		}

	}

	return;

}



int main() {

	cin >> n;

	inc(i, n) {

		int a;

		cin >> a;

		a--;

		v[i].EB(a, 1);

	}

	

	inc(i, n) { d[i] = n + 1; }

	dijkstra(0, v, d);

	if(d[1] == n + 1) { d[1] = -1; }

	

	cout << d[1] << endl;

	

	return 0;

}


// Faster C++ solution for the same problem (measured speedup: 3.5394462698615516x):
#include <bits/stdc++.h>

using namespace std;



typedef long long   signed int LL;

typedef long long unsigned int LU;



#define incID(i, l, r) for(int i = (l)    ; i <  (r); i++)

#define incII(i, l, r) for(int i = (l)    ; i <= (r); i++)

#define decID(i, l, r) for(int i = (r) - 1; i >= (l); i--)

#define decII(i, l, r) for(int i = (r)    ; i >= (l); i--)

#define  inc(i, n) incID(i, 0, n)

#define inc1(i, n) incII(i, 1, n)

#define  dec(i, n) decID(i, 0, n)

#define dec1(i, n) decII(i, 1, n)



#define inII(v, l, r) ((l) <= (v) && (v) <= (r))

#define inID(v, l, r) ((l) <= (v) && (v) <  (r))



#define PB push_back

#define EB emplace_back

#define MP make_pair

#define FI first

#define SE second

#define UB upper_bound

#define LB lower_bound

#define PQ priority_queue



#define  ALL(v)  v.begin(),  v.end()

#define RALL(v) v.rbegin(), v.rend()

#define  FOR(it, v) for(auto it =  v.begin(); it !=  v.end(); ++it)

#define RFOR(it, v) for(auto it = v.rbegin(); it != v.rend(); ++it)



template<typename T> bool   setmin(T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }

template<typename T> bool   setmax(T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }

template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }

template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }

template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }

template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }



// ---- ----



int n, a[100000];



int main() {

	cin >> n;

	inc(i, n) { cin >> a[i]; a[i]--; }

	

	int ans = 0, p = 0;

	while(true) {

		int t = a[p];

		a[p] = -1;

		p = t;

		ans++;

		if(p == 1) { break; }

		if(p == -1) { ans = -1; break; }

	}

	

	cout << ans << endl;

	

	return 0;

}