#include <bits/stdc++.h>
using namespace std;
int n, m, k, i, o, l, ans, p, j, s, t, a[100000 + 10], used[100000 + 10];
int main() {
  cin >> n >> s >> t;
  for (i = 1; i <= n; i++) cin >> a[i];
  while (s != t) {
    if (used[s] == 1) {
      cout << -1;
      return 0;
    }
    used[s] = 1;
    s = a[s];
    ans++;
  }
  cout << ans;
}
