#include <bits/stdc++.h>
using namespace std;
int a[100000 + 5], b[100000 + 5];
int n, s, t;
int main() {
  cin >> n >> s >> t;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  int cnt = 0;
  while (s != t && !b[s]) {
    cnt++;
    b[s] = 1;
    s = a[s];
  }
  if (s != t) {
    cout << -1 << endl;
  } else {
    cout << cnt << endl;
  }
}
