#include <bits/stdc++.h>
int main() {
  int i, j, n, s, t, c = 0, f = 0;
  scanf("%d%d%d", &n, &s, &t);
  int a[n];
  for (i = 0; i < n; i++) {
    scanf("%d", &a[i]);
  }
  if (s != t) {
    s = s - 1;
    t = t - 1;
    j = s;
    for (i = 0; i < n; i++) {
      j = a[j] - 1;
      c++;
      if (j == t) {
        f = 1;
        break;
      }
    }
    if (f == 1)
      printf("%d", c);
    else
      printf("-1");
  } else
    printf("0");
}
