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