#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, s, t;
  int p = 0, q = 0;
  cin >> n >> s >> t;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  if (s == t) {
    cout << "0";
    return 0;
  }
  if (a[s - 1] == s && s != t) {
    cout << "-1";
    return 0;
  }
  int pos = s;
  int b = s;
  while (true) {
    pos = a[b - 1];
    b = pos;
    q++;
    if (pos == t) {
      cout << q;
      return 0;
    }
    if (pos == s) {
      cout << "-1";
      return 0;
    }
  }
}
