#include <bits/stdc++.h>
using namespace std;
int visit[100005];
int main() {
  int n, s, e, i, a[100005], cnt, val;
  cin >> n >> s >> e;
  for (i = 1; i <= n; i++) cin >> a[i];
  cnt = 1;
  while (visit[s] == 0) {
    visit[s] = cnt;
    cnt++;
    s = a[s];
  }
  cout << visit[e] - 1;
}
