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