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