#include <bits/stdc++.h>
using namespace std;
int solve(int arr[], int n, int s, int t) {
  int cnt = 0;
  if (s == t) {
    return 0;
  }
  while (cnt < n) {
    s = arr[s - 1];
    cnt = cnt + 1;
    if (s == t) {
      return cnt;
    }
  }
  return -1;
}
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  cout << solve(arr, n, s, t);
  return 0;
}
