#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t, ct = 0, i, p[100002] = {0};
  cin >> n >> s >> t;
  for (i = 1; i <= n; i++) cin >> p[i];
  while (ct <= n) {
    if (s == t) {
      break;
    } else {
      s = p[s];
      ct++;
    }
  }
  if (ct == n + 1) {
    cout << -1;
  } else
    cout << ct;
  return 0;
}
