#include <bits/stdc++.h>
using namespace std;
long long int n, st, e, arr[100000], counter, init;
string s;
int main() {
  cin >> n >> st >> e;
  for (int i = 0; i < n; i++) cin >> arr[i];
  if (st == e) {
    cout << 0 << endl;
    return 0;
  }
  init = arr[st - 1];
  counter++;
  while (init != st) {
    if (init == e) break;
    init = arr[init - 1];
    counter++;
  }
  if (init == e)
    cout << counter << endl;
  else
    cout << -1 << endl;
}
