import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    int n;
    int next[];
    boolean used[];

    public void solve() throws IOException {
        n = nextInt();
        next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        }
        int cnt = 0;
        used = new boolean[n];
        int k = 0;
        while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        }
        if(k == 1) out.print(cnt);
        else out.print(-1);

    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
} import java.io.*; io.* java import java.lang.reflect.Array; Array java.lang.reflect import java.util.*; util.* java public class Main {

    int n;
    int next[];
    boolean used[];

    public void solve() throws IOException {
        n = nextInt();
        next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        }
        int cnt = 0;
        used = new boolean[n];
        int k = 0;
        while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        }
        if(k == 1) out.print(cnt);
        else out.print(-1);

    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
} Main int n; n int next[]; next boolean used[]; used BufferedReader br; br StringTokenizer sc; sc PrintWriter out; out public void solve() throws IOException {
        n = nextInt();
        next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        }
        int cnt = 0;
        used = new boolean[n];
        int k = 0;
        while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        }
        if(k == 1) out.print(cnt);
        else out.print(-1);

    } solve {
        n = nextInt();
        next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        }
        int cnt = 0;
        used = new boolean[n];
        int k = 0;
        while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        }
        if(k == 1) out.print(cnt);
        else out.print(-1);

    } n = nextInt() n nextInt() nextInt next = new int[n] next new int[n] n for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        } int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
            next[i] = nextInt() - 1;
        } {
            next[i] = nextInt() - 1;
        } next[i] = nextInt() - 1 next[i] next i nextInt() - 1 nextInt() nextInt 1 int cnt = 0; cnt 0 used = new boolean[n] used new boolean[n] n int k = 0; k 0 while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        } k != 1 && !used[k] k != 1 k 1 !used[k] used[k] used k {
            used[k] = true;
            k = next[k];
            cnt++;
        } used[k] = true used[k] used k true k = next[k] k next[k] next k cnt++ cnt if(k == 1) out.print(cnt);
        else out.print(-1); k == 1 k 1 out.print(cnt) out.print out cnt out.print(-1) out.print out -1 1 public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    } main {
        Locale.setDefault(Locale.US);
        new Main().run();
    } Locale.setDefault(Locale.US) Locale.setDefault Locale Locale.US Locale Locale.US new Main().run() new Main().run new Main() String[] args args void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    } run {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    } try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        } Exception e {
            e.printStackTrace();
            System.exit(1);
        } e.printStackTrace() e.printStackTrace e System.exit(1) System.exit System 1 {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } br = new BufferedReader(new InputStreamReader(System.in)) br new BufferedReader(new InputStreamReader(System.in)) out = new PrintWriter(System.out) out new PrintWriter(System.out) solve() solve out.close() out.close out String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    } nextToken {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    } while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        } sc == null || !sc.hasMoreTokens() sc == null sc null !sc.hasMoreTokens() sc.hasMoreTokens() sc.hasMoreTokens sc {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        } try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            } catch (Exception e) {
                return null;
            } Exception e {
                return null;
            } return null; null {
                sc = new StringTokenizer(br.readLine());
            } sc = new StringTokenizer(br.readLine()) sc new StringTokenizer(br.readLine()) return sc.nextToken(); sc.nextToken() sc.nextToken sc int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    } nextInt {
        return Integer.parseInt(nextToken());
    } return Integer.parseInt(nextToken()); Integer.parseInt(nextToken()) Integer.parseInt Integer nextToken() nextToken long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    } nextLong {
        return Long.parseLong(nextToken());
    } return Long.parseLong(nextToken()); Long.parseLong(nextToken()) Long.parseLong Long nextToken() nextToken public class Main {

    int n;
    int next[];
    boolean used[];

    public void solve() throws IOException {
        n = nextInt();
        next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        }
        int cnt = 0;
        used = new boolean[n];
        int k = 0;
        while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        }
        if(k == 1) out.print(cnt);
        else out.print(-1);

    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
} public class Main {

    int n;
    int next[];
    boolean used[];

    public void solve() throws IOException {
        n = nextInt();
        next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        }
        int cnt = 0;
        used = new boolean[n];
        int k = 0;
        while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        }
        if(k == 1) out.print(cnt);
        else out.print(-1);

    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
} Main
import java.io.*;
import java.lang.reflect.Array;
import java.util.*;

public class Main {

    int n;
    int next[];
    boolean used[];

    public void solve() throws IOException {
        n = nextInt();
        next = new int[n];
        for (int i = 0; i < n; i++) {
            next[i] = nextInt() - 1;
        }
        int cnt = 0;
        used = new boolean[n];
        int k = 0;
        while(k != 1 && !used[k]){
            used[k] = true;
            k = next[k];
            cnt++;
        }
        if(k == 1) out.print(cnt);
        else out.print(-1);

    }


    BufferedReader br;
    StringTokenizer sc;
    PrintWriter out;

    public static void main(String[] args) throws IOException {
        Locale.setDefault(Locale.US);
        new Main().run();
    }

    void run() throws IOException {
        try {
            br = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
//            br = new BufferedReader(new FileReader("queue.in"));
//            out = new PrintWriter(new File("queue.out"));
            solve();
            out.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    String nextToken() throws IOException {
        while (sc == null || !sc.hasMoreTokens()) {
            try {
                sc = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                return null;
            }
        }
        return sc.nextToken();
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
}