#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  int A[n + 1];
  for (int i = 1; i < n + 1; i++) cin >> A[i];
  bool visited[n + 1];
  memset(visited, 0, sizeof(visited));
  bool pos = 1;
  int moves = 0;
  while (s != t) {
    if (visited[s]) {
      pos = 0;
      break;
    }
    visited[s] = 1;
    s = A[s];
    moves++;
  }
  if (pos)
    cout << moves << endl;
  else
    cout << -1 << endl;
  return 0;
}
