#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  vector<int> a(0);
  a.push_back(-1);
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a.push_back(x);
  }
  int v[999999] = {0};
  int ans = 0;
  while (1) {
    if (s == t) {
      cout << ans << endl;
      return 0;
    }
    if (v[s]) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = 1;
    s = a[s];
    ans++;
  }
  return 0;
}
