#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t, x, adj[100010];
  cin >> n >> s >> t;
  s--;
  t--;
  for (int i = 0; i < n; i++) {
    cin >> x;
    adj[i] = x - 1;
  }
  int steps = 0;
  int vis[100010] = {0};
  while (s != t) {
    vis[s] = 1;
    s = adj[s];
    if (vis[s]) {
      steps = -1;
      break;
    }
    steps++;
  }
  cout << steps << endl;
  return 0;
}
