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