#include <bits/stdc++.h>
using namespace std;
long long arr[100005] = {};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, i, f, x, w = 0, p, s;
  cin >> n >> i >> f;
  s = f;
  for (int k = 1; k <= n; ++k) {
    cin >> x;
    arr[x] = k;
  }
  if (i == f) {
    cout << "0\n";
    exit(0);
  }
  while (1) {
    p = arr[f];
    w++;
    if (p == i) {
      cout << w << "\n";
      exit(0);
    } else if (p == f || p == s) {
      cout << -1 << "\n";
      exit(0);
    } else
      f = p;
  }
  return 0;
}
