#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, s, t;
  cin >> N >> s >> t;
  vector<int> A(N);
  for (long long i = 0; i < N; i++) {
    cin >> A[i];
  }
  if (s == t) {
    cout << 0;
    return 0;
  }
  int ss = s, ans = 0;
  while (t != ss) {
    if (ans > 2 * N) {
      cout << -1;
      return 0;
    }
    ss = A[ss - 1];
    ans++;
    if (ss == s) {
      cout << -1;
      return 0;
    }
  }
  cout << ans;
  return 0;
}
