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