#include <bits/stdc++.h>
int main() {
  int n, s, t;
  std::cin >> n >> s >> t;
  int ans = 0;
  if (s != t) {
    int p[n + 1];
    for (int i = 1; i <= n; i++) {
      std::cin >> p[i];
    }
    while (1) {
      int ts = p[s];
      p[s] = 0;
      s = ts;
      ans++;
      if (t == s || 0 == s) {
        break;
      }
    }
    if (0 == s) ans = -1;
  }
  std::cout << ans << "\n";
  return 0;
}
