#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, e, i, flag = 0;
  cin >> n >> s >> e;
  int arr[n + 1];
  for (i = 1; i <= n; i++) cin >> arr[i];
  for (i = 1; i <= n; i++) {
    if (s == e) {
      flag = 1;
      i = 0;
      break;
    }
    if (arr[s] == e) {
      flag = 1;
      break;
    } else {
      s = arr[s];
    }
  }
  if (flag == 0)
    cout << "-1";
  else
    cout << i;
  return 0;
}
