#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, i, count = 0, s, t, temp, flag = 0, p;
  cin >> n;
  long long a[n];
  cin >> s >> t;
  p = s;
  for (i = 0; i < n; i++) {
    cin >> a[i];
  }
  temp = a[t - 1];
  if (s == t)
    cout << "0" << endl;
  else {
    while (1) {
      i = a[s - 1];
      if (a[i - 1] == temp) {
        if (count == 0 && s == t)
          cout << "0" << endl;
        else
          cout << count + 1 << endl;
        break;
      } else if (a[s - 1] == s || a[s - 1] == p) {
        flag = 1;
        break;
      }
      s = i;
      count++;
    }
    if (flag == 1) cout << "-1" << endl;
  }
}
