#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, i = 0, j, m, a, b = 0, c = 0, temp;
  int s, t;
  cin >> n >> s >> t;
  int arr[n + 1];
  for (i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  if (s == t) {
    cout << 0;
    return 0;
  }
  temp = s;
  i = 0;
  while (1) {
    i++;
    temp = arr[temp];
    if (temp == t) {
      cout << i;
      return 0;
    }
    if (temp == s) {
      cout << -1;
      return 0;
    }
  }
}
