#include <bits/stdc++.h>
using namespace std;
int a[100005], visit[100005];
int main() {
  int n, s, t;
  scanf("%d%d%d", &n, &s, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  memset(visit, 0, sizeof(visit));
  int cnt = 0;
  while (1) {
    if (visit[s]) {
      printf("-1\n");
      return 0;
    }
    if (s == t) {
      printf("0\n");
      return 0;
    }
    if (a[s] == s) {
      printf("-1\n");
      return 0;
    }
    visit[s] = 1;
    s = a[s];
    cnt++;
    if (s == t) {
      printf("%d\n", cnt);
      return 0;
    }
  }
  return 0;
}
