#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  int a[n], b[100000] = {};
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int cnt = 0; cnt <= n; cnt++) {
    if (s == t) {
      cout << cnt << endl;
      return 0;
    }
    b[s - 1] = 1;
    s = a[s - 1];
    if (b[s - 1]) {
      cout << -1 << endl;
      return 0;
    }
  }
  return 0;
}
