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