#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long int n, s, t;
  cin >> n >> s >> t;
  vector<long long int> arr(n + 1);
  vector<bool> vis(n + 1, false);
  for (long long int i = 1; i <= n; i++) cin >> arr[i];
  if (s == t) {
    cout << "0\n";
  } else {
    long long int index = s, steps = 1;
    bool flag = true;
    while (arr[index] != t) {
      if (vis[index]) {
        flag = false;
        cout << "-1\n";
        break;
      }
      vis[index] = true;
      index = arr[index];
      steps++;
    }
    if (flag) cout << steps << "\n";
  }
}
int main() {
  solve();
  return 0;
}
