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