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