#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  vector<int> edge(1 + n);
  for (int i = 1; i <= n; i++) {
    cin >> edge[i];
  }
  int ans = 0;
  while (s != t) {
    ans++;
    s = edge[s];
    if (ans == 1000000) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
  return 0;
}
