#include <bits/stdc++.h>
using namespace std;
int main() {
  long int n, s, t;
  cin >> n >> s >> t;
  vector<long int> vec;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    vec.push_back(x);
  }
  if (s == t) return cout << "0" << endl, 0;
  for (int i = 1; i <= n; i++) {
    s = vec[s - 1];
    if (s == t) return cout << i << endl, 0;
  }
  return cout << -1 << endl, 0;
}
