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