#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  while (t--) {
    long long int n, a, b;
    cin >> n >> a >> b;
    vector<long long int> arr(n + 1);
    for (long long int i = 1; i < n + 1; ++i) {
      cin >> arr[i];
    }
    long long int x = a;
    long long int shuffle = 0;
    long long int i = a;
    while (x != b) {
      if (shuffle != 0 && x == a) {
        break;
      }
      x = arr[i];
      i = x;
      shuffle++;
    }
    if (x != b) {
      cout << -1;
    } else {
      cout << shuffle;
    }
  }
  return 0;
}
