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