#include <bits/stdc++.h>
using namespace std;
int main() {
  bool flag;
  int n, second, t, b[100000], cnt = 0;
  cin >> n >> second >> t;
  for (int i = 1; i <= n; i++) cin >> b[i];
  if (second == t) {
    cout << 0;
    return 0;
  }
  for (cnt = 1; cnt <= n + 1; cnt++) {
    int x = b[second];
    if (x == t) {
      flag = true;
      break;
    }
    if (second == x) {
      flag = false;
      break;
    }
    second = x;
  }
  if (flag == true)
    cout << cnt;
  else
    cout << -1;
  return 0;
}
