#include <bits/stdc++.h>
int main() {
  int n, s, t, i, count = 0, check = 0;
  scanf("%d %d %d", &n, &s, &t);
  int cng[n + 1];
  for (i = 1; i <= n; i++) {
    scanf("%d", &cng[i]);
  }
  if (check == 1) {
    printf("-1");
    return 0;
  }
  while (count < n && s != t) {
    s = cng[s];
    count++;
  }
  if (count == n) {
    printf("-1");
    return 0;
  }
  printf("%d", count);
  return 0;
}
