import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

public class Main
{
    int n;
    int a[] = new int[100001];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
} import java.util.Scanner; Scanner java.util import java.util.Arrays; Arrays java.util import java.util.Comparator; Comparator java.util public class Main
{
    int n;
    int a[] = new int[100001];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
} Main int n; n int a[] = new int[100001]; a new int[100001] 100001 public static void main(String args[])
    {
	new Main().solve();
    } main {
	new Main().solve();
    } new Main().solve() new Main().solve new Main() String args[] args void solve()
    {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    } solve {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    } in() in int cnt = 0; cnt 0 int now = 1; now 1 while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	} a[now] != -1 a[now] a now -1 1 {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	} int tmp = now; tmp now now = a[now] now a[now] a now a[tmp] = -1 a[tmp] a tmp -1 1 cnt++ cnt if(now == 2) break; now == 2 now 2 break; if(now == 2) out(cnt);
	else         out(-1); now == 2 now 2 out(cnt) out cnt out(-1) out -1 1 void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    } in {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    } Scanner sc = new Scanner(System.in); sc new Scanner(System.in) n = sc.nextInt() n sc.nextInt() sc.nextInt sc for(int i = 1; i <= n; i++) a[i] = sc.nextInt(); int i = 1; int i = 1; i 1 i <= n i n i++ i++ i a[i] = sc.nextInt(); a[i] = sc.nextInt() a[i] a i sc.nextInt() sc.nextInt sc void out()
    {
	
    } out {
	
    } void out(int ans)
    {
	System.out.println(ans);
    } out {
	System.out.println(ans);
    } System.out.println(ans) System.out.println System.out System System.out ans int ans ans public class Main
{
    int n;
    int a[] = new int[100001];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
} public class Main
{
    int n;
    int a[] = new int[100001];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
} Main
import java.util.Scanner;
import java.util.Arrays;
import java.util.Comparator;

public class Main
{
    int n;
    int a[] = new int[100001];
    
    public static void main(String args[])
    {
	new Main().solve();
    }
    
    void solve()
    {
	in();

	int cnt = 0;
	int now = 1;
	
	while(a[now] != -1) {
	    int tmp = now;
	    now = a[now];
	    a[tmp] = -1;
	    cnt++;
	    if(now == 2) break;
	}
	
	if(now == 2) out(cnt);
	else         out(-1);
    }

    void in()
    {
	Scanner sc = new Scanner(System.in);
	n = sc.nextInt();
	for(int i = 1; i <= n; i++) a[i] = sc.nextInt();
    }

    void out()
    {
	
    }
    
    void out(int ans)
    {
	System.out.println(ans);
    }
}
