#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n, s, t;
  cin >> n >> s >> t;
  vector<long long> wp;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    wp.push_back(--x);
  }
  if (s == t) {
    cout << "0";
    return;
  }
  s = s - 1;
  --t;
  for (long long i = 1; i <= n; i++) {
    s = wp[s];
    if (s == t) {
      cout << i;
      return;
    }
  }
  cout << "-1";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  cout << "\n";
  return 0;
}
