#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 123;
int n, s, t;
int p[N];
int main() {
  cin >> n >> s >> t;
  for (int i = 1; i <= n; ++i) scanf("%d", &p[i]);
  int i = 0;
  while (i <= n) {
    if (s == t) {
      cout << i;
      return 0;
    }
    i++;
    s = p[s];
  }
  cout << -1;
  return 0;
}
