#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  int s, t;
  cin >> s >> t;
  s--;
  t--;
  int arr[n];
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    arr[i]--;
  }
  bool flag = false;
  int ctr = 0;
  int turn = n;
  int curr_pos = s;
  while (turn--) {
    int dummy[n];
    if (t == s) {
      flag = true;
      break;
    }
    s = arr[s];
    ctr++;
  }
  if (flag)
    cout << ctr;
  else
    cout << "-1";
}
