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