#include <bits/stdc++.h>
using namespace std;
int n, s, t, k;
int P[100001];
int PP[10001];
int main() {
  cin >> n >> s >> t;
  for (int i = 1; i <= n; ++i) cin >> P[i];
  int ps = s;
  while ((ps != t) and (k <= n)) {
    ps = P[ps];
    k++;
  }
  if (ps == t) {
    cout << k;
    return 0;
  } else {
    cout << -1;
  }
  return 0;
}
