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