import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    int cnt = 0;

    int a[] = new int[num];
    int b = 1;

    for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    }

    for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    }

    if (cnt > a.length) {
      cnt = -1;
    }

    System.out.println(cnt);
  }

  public static int getLight(int a[], int num) {
    return a[num - 1];
  }

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

  public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    int cnt = 0;

    int a[] = new int[num];
    int b = 1;

    for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    }

    for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    }

    if (cnt > a.length) {
      cnt = -1;
    }

    System.out.println(cnt);
  }

  public static int getLight(int a[], int num) {
    return a[num - 1];
  }

} Main public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    int cnt = 0;

    int a[] = new int[num];
    int b = 1;

    for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    }

    for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    }

    if (cnt > a.length) {
      cnt = -1;
    }

    System.out.println(cnt);
  } main {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    int cnt = 0;

    int a[] = new int[num];
    int b = 1;

    for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    }

    for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    }

    if (cnt > a.length) {
      cnt = -1;
    }

    System.out.println(cnt);
  } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int num = Integer.parseInt(br.readLine()); num Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br int cnt = 0; cnt 0 int a[] = new int[num]; a new int[num] num int b = 1; b 1 for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    } int i = 0; int i = 0; i 0 i < a.length i a.length a a.length i++ i++ i {
      a[i] = Integer.parseInt(br.readLine());
    } {
      a[i] = Integer.parseInt(br.readLine());
    } a[i] = Integer.parseInt(br.readLine()) a[i] a i Integer.parseInt(br.readLine()) Integer.parseInt Integer br.readLine() br.readLine br for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    } int i = 0; int i = 0; i 0 i < a.length + 1 i a.length + 1 a.length a a.length 1 i++ i++ i {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    } {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    } b = getLight(a, b) b getLight(a, b) getLight a b cnt++ cnt if (b == 2) {
        break;
      } b == 2 b 2 {
        break;
      } break; if (cnt > a.length) {
      cnt = -1;
    } cnt > a.length cnt a.length a a.length {
      cnt = -1;
    } cnt = -1 cnt -1 1 System.out.println(cnt) System.out.println System.out System System.out cnt String[] args args public static int getLight(int a[], int num) {
    return a[num - 1];
  } getLight {
    return a[num - 1];
  } return a[num - 1]; a[num - 1] a num - 1 num 1 int a[] a int num num public class Main {

  public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    int cnt = 0;

    int a[] = new int[num];
    int b = 1;

    for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    }

    for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    }

    if (cnt > a.length) {
      cnt = -1;
    }

    System.out.println(cnt);
  }

  public static int getLight(int a[], int num) {
    return a[num - 1];
  }

} public class Main {

  public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    int cnt = 0;

    int a[] = new int[num];
    int b = 1;

    for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    }

    for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    }

    if (cnt > a.length) {
      cnt = -1;
    }

    System.out.println(cnt);
  }

  public static int getLight(int a[], int num) {
    return a[num - 1];
  }

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws NumberFormatException, IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    int num = Integer.parseInt(br.readLine());
    int cnt = 0;

    int a[] = new int[num];
    int b = 1;

    for (int i = 0; i < a.length; i++) {
      a[i] = Integer.parseInt(br.readLine());
    }

    for (int i = 0; i < a.length + 1; i++) {
      b = getLight(a, b);
      cnt++;

      if (b == 2) {
        break;
      }
    }

    if (cnt > a.length) {
      cnt = -1;
    }

    System.out.println(cnt);
  }

  public static int getLight(int a[], int num) {
    return a[num - 1];
  }

}
