#include <bits/stdc++.h>
using namespace std;
int main() {
  int long n, t, j, s, k, m, cou = 0;
  cin >> n >> s >> t;
  int long *a = new int long[n];
  for (j = 0; j < n; j++) cin >> a[j];
  while (s != t && cou < n + 2) {
    cou++;
    if (a[s - 1] == t) break;
    s = a[s - 1];
  }
  if (cou < n)
    cout << cou;
  else
    cout << -1;
  return 0;
}
