#include <iostream>
#include <vector>
using namespace std;
int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (auto& i : a) cin >> i;
    int c = 1, cnt = 0;
    while (c != 2 && cnt <= N) {
        c = a[c - 1];
        cnt++;
    }
    cout << (cnt > N ? -1 : cnt) << endl;
}