#include <bits/stdc++.h>
using namespace std;
int n, s, t, a[100000 + 2], ans;
bool p;
void DFS(int x) {
  if (x == s) return;
  ans++;
  if (x == t) {
    p = 1;
    return;
  }
  DFS(a[x - 1]);
}
int main() {
  cin >> n >> s >> t;
  for (int i = 0; i < n; i++) cin >> a[i];
  DFS(a[s - 1]);
  if (s == t)
    cout << 0;
  else if (!p)
    cout << -1;
  else
    cout << ans;
  cout << endl;
  return 0;
}
