#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  vector<int> nums(n + 1);
  for (int i = 1; i <= n; i++) {
    cin >> nums[i];
  }
  vector<bool> visited(n + 1, false);
  int count = 0;
  while (s != t && !visited[s]) {
    visited[s] = true;
    s = nums[s];
    count++;
  }
  if (s == t) {
    cout << count;
  } else {
    cout << "-1";
  }
  return 0;
}
