#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 123;
const long long inf = 1e9 + 123;
const long double INF = 1e12 + 123;
const int mod = 1e7 + 123;
int n, second, t, p[maxn];
int len;
int main() {
  cin >> n >> second >> t;
  for (int i = 1; i <= n; ++i) {
    cin >> p[i];
  }
  int x = second;
  int y = t;
  while (x != y) {
    if (p[x] == second) {
      cout << -1;
      return 0;
    }
    len++;
    x = p[x];
  }
  cout << len;
  return 0;
}
