#include <bits/stdc++.h>
using namespace std;
int n, m;
int i, j, k, l;
int a[333333];
int u[333333];
int main() {
  ios_base::sync_with_stdio(0);
  int X, Y;
  cin >> n >> X >> Y;
  for (int _ = 0; _ < n; ++_) cin >> (a + 1)[_];
  ;
  memset(u, -1, sizeof(u));
  for (i = 1; i <= n; ++i)
    if (i == X) {
      k = 0;
      for (j = i; u[j] == -1; j = a[j]) u[j] = k++;
    }
  cout << u[Y] << endl;
  return 0;
}
