#include <bits/stdc++.h>
using namespace std;
int xorr(int a, int b) { return ((a | b) & (~a | ~b)); }
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  int a[n + 1];
  for (int i = 1; i <= n; i++) cin >> a[i];
  vector<bool> b(n + 1, false);
  int k = 0;
  if (s == t) {
    cout << "0" << endl;
    return 0;
  }
  for (int i = s; b[i] == false;) {
    k++;
    b[i] = true;
    if (a[i] == t) {
      cout << k << endl;
      return 0;
    }
    i = a[i];
  }
  cout << "-1" << endl;
  return 0;
}
