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