#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  vector<int> v(n);
  int count = 0;
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    v[i]--;
  }
  int index = s;
  vector<int> pos;
  int r = s - 1;
  t--;
  for (int i = 0; i < n - 1; i++) {
    if (r == t) break;
    r = v[r];
    count++;
  }
  if (r != t)
    cout << -1 << endl;
  else
    cout << count << endl;
  return 0;
}
