#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n, s, t;
  cin >> n >> s >> t;
  long long q, p[n], cnt = 0, in, f = 0;
  for (long long i = 0; i < n; i++) cin >> p[i];
  for (long long i = 0; i < n; i++) {
    q = p[i] - 1;
    in = q;
    cnt = 0;
    if (q == s - 1) {
      if ((p[q] - 1) == (t - 1)) {
        if (p[q] - 1 != q) cnt += 1;
        break;
      } else {
        cnt += 1;
        q = p[q] - 1;
        while (true) {
          q = p[q] - 1;
          cnt += 1;
          if (q == in) break;
          if (q == t - 1) break;
        }
        if (q == t - 1 && q == in) {
          cnt = 0;
          break;
        }
        if (q == t - 1) break;
        if (q == in) {
          f = 1;
          break;
        }
      }
    }
  }
  if (f == 0)
    cout << cnt;
  else
    cout << -1;
  return 0;
}
