#include <bits/stdc++.h>
using namespace std;
const int maxn = 2 * 1e5 + 10, mod = 1e9 + 7;
long long a[maxn], d[maxn];
bool mark[maxn];
long long dfs(int v, int p) {
  mark[v] = 1;
  if (v == p) return 0;
  if (mark[a[v]]) return -1;
  int k = dfs(a[v], p);
  return (k == -1 ? -1 : k + 1);
}
int main() {
  ios::sync_with_stdio(0);
  long long n, s, t;
  cin >> n >> s >> t;
  for (int i = 1; i <= n; i++) cin >> a[i];
  cout << dfs(s, t) << endl;
  return 0;
}
