#include <bits/stdc++.h>
using namespace std;
int neigh[(int)1e6];
int vis[(int)1e6];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(vis, 0, sizeof(vis));
  int n, second, t;
  cin >> n >> second >> t;
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    neigh[i + 1] = a;
  }
  int d = 0;
  int first = 0;
  while (second != t) {
    if (vis[second]) {
      first = 1;
      break;
    }
    vis[second] = 1;
    second = neigh[second];
    d++;
  }
  if (first == 1)
    cout << -1 << '\n';
  else
    cout << d << '\n';
  return 0;
}
