#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  int arr[n + 1];
  arr[0] = 0;
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  unordered_set<int> m;
  int step = 0;
  while (s != t) {
    s = arr[s];
    if (m.find(s) != m.end()) {
      step = -1;
      break;
    } else {
      step++;
      m.insert(s);
    }
  }
  cout << step << endl;
  return 0;
}
