import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	}
} import java.io.PrintWriter; PrintWriter java.io import java.util.ArrayList; ArrayList java.util import java.util.Collection; Collection java.util import java.util.Collections; Collections java.util import java.util.HashMap; HashMap java.util import java.util.List; List java.util import java.util.Map; Map java.util import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	}
} Main public static void main(String[] args) {
		solve();
	} main {
		solve();
	} solve() solve String[] args args public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	} solve {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) PrintWriter out = new PrintWriter(System.out); out new PrintWriter(System.out) int n = sc.nextInt(); n sc.nextInt() sc.nextInt sc List<Integer> a = new ArrayList<>(); a new ArrayList<>() for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            int t = sc.nextInt();
            t--;
            a.add(t);
        } {
            int t = sc.nextInt();
            t--;
            a.add(t);
        } int t = sc.nextInt(); t sc.nextInt() sc.nextInt sc t-- t a.add(t) a.add a t int ans = 0; ans 0 int now = 0; now 0 for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        } int i = 0; int i = 0; i 0 i < n+1 i n+1 n 1 i++ i++ i {
            if(now == 1)break;
            ans++;
            now = a.get(now);
        } {
            if(now == 1)break;
            ans++;
            now = a.get(now);
        } if(now == 1)break; now == 1 now 1 break; ans++ ans now = a.get(now) now a.get(now) a.get a now if(ans > n) ans = -1; ans > n ans n ans = -1 ans -1 1 out.println(ans) out.println out ans out.flush() out.flush out public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	}
} public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	}
} Main
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		solve();
	}

	public static void solve() {
        Scanner sc = new Scanner(System.in);
        PrintWriter out = new PrintWriter(System.out);
        int n = sc.nextInt();
        List<Integer> a = new ArrayList<>();
        for(int i = 0; i < n; i++){
            int t = sc.nextInt();
            t--;
            a.add(t);
        }
        int ans = 0;
        int now = 0;
        for(int i = 0; i < n+1; i++){
            if(now == 1)break;
            ans++;
            now = a.get(now);
        }
        if(ans > n) ans = -1;
        out.println(ans);
        out.flush();
	}
}