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