#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
long long n, m, a[N], b[N], k = 0, l = 0, i, j = 0, mn = 0, mx = 0, ans = 0,
                            r1 = 0, r2 = 0, r3 = 0, t, q, v = 0;
string d1, d3, d2, s;
pair<long long, long long> g[N];
char lk, kl = 'a';
int main() {
  cin >> n >> k >> r1;
  for (i = 1; i <= n; i++) cin >> a[i];
  i = 0;
  while (k != r1 && i <= n) k = a[k], i++;
  if (k == r1)
    cout << i;
  else
    cout << -1;
  cout << "\n";
  return 0;
}
