#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) {
    std::cin >> v[i];
  }
  int count = 0;
  while (s != t && v[s - 1] != 0) {
    int temp = v[s - 1];
    v[s - 1] = 0;
    s = temp;
    count++;
  }
  std::cout << ((s == t) ? count : -1) << "\n";
  return 0;
}
