#include <bits/stdc++.h>
using namespace std;
int main(int argc, char const *argv[]) {
  int n, s, t;
  cin >> n >> s >> t;
  int final[n + 1];
  int flag[n + 1];
  for (int i = 1; i <= n; ++i) {
    flag[i] = 0;
    cin >> final[i];
  }
  int count = 0;
  flag[s] = 1;
  while (s != t) {
    if (flag[final[s]] == 1) {
      cout << "-1";
      return 0;
    } else {
      s = final[s];
      flag[s] = 1;
      count++;
    }
  }
  cout << count;
  return 0;
}
