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