#include <bits/stdc++.h>
using namespace std;
const int inf = 1000000000;
const int mod = 1000000007;
const double pi = acos(-1.0);
const double eps = 1e-9;
const double e = 2.7182818284590452353602874713527;
inline int fmin(int a, int b) { return a < b ? a : b; }
inline int fmax(int a, int b) { return a > b ? a : b; }
inline void swap(int &x, int &y) {
  int t;
  t = x, x = y, y = t;
}
inline int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
inline int lcm(int a, int b) { return a / gcd(a, b) * b; }
int a[100005];
int main() {
  int n, s, t, ans = -1, i;
  while (cin >> n >> s >> t) {
    ans = -1;
    for (i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n; i++) {
      if (s == t) {
        ans = i;
        break;
      }
      s = a[s];
    }
    cout << ans << endl;
    cout << endl;
  }
  return 0;
}
