#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 7;
int s, t, n;
int p[maxn];
int main() {
  cin >> n >> s >> t;
  for (int i = 1; i <= n; ++i) cin >> p[i];
  bool fnd = false;
  int cnt = 0;
  int st = 0;
  int start = s;
  while (true) {
    if (start == t) {
      fnd = true;
      break;
    }
    if (st > 1) break;
    if (start == s) st++;
    cnt++;
    start = p[start];
  }
  if (fnd)
    cout << cnt << endl;
  else
    cout << -1 << endl;
}
