#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const long long INF64 = 1e18;
const int MOD = 1e9 + 7;
const long double EPS = 1e-9;
const long double PI = acosl(-1.0);
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  vector<int> p(n);
  for (int i = 0; i < int(n); i++) {
    cin >> p[i];
  }
  int k = 0;
  while (k != n) {
    if (s == t) {
      cout << k;
      return 0;
    }
    s = p[s - 1];
    k++;
  }
  cout << -1;
  return 0;
}
