#include <bits/stdc++.h>
using namespace std;
int n, tmp, ini, fin, res = 1, check = 0;
int main() {
  cin >> n >> ini >> fin;
  int* pos = new int[n];
  for (int i = 0; i < n; i++) cin >> pos[i];
  tmp = ini - 1;
  do {
    if (pos[tmp] == fin) {
      check = 1;
      break;
    }
    tmp = pos[tmp] - 1;
    res++;
  } while (pos[tmp] != ini);
  if (ini == fin)
    cout << 0;
  else if (!check)
    cout << -1;
  else
    cout << res;
  delete[] pos;
  return 0;
}
