#include <bits/stdc++.h>
using namespace std;
void boost() {
  std::ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
int arr[100001];
int main() {
  boost();
  int first;
  int n, s, t;
  cin >> n >> s >> t;
  for (first = 0; first < n; first++) {
    int x;
    cin >> x;
    x--;
    arr[x] = first;
  }
  long long cnt = 0;
  s--;
  t--;
  while (1) {
    if (t == s) {
      cout << cnt;
      return 0;
    }
    int x = arr[t];
    cnt++;
    if (x == s) {
      cout << cnt;
      return 0;
    }
    if (x == -2) break;
    arr[t] = -2;
    t = x;
  }
  cout << -1;
  return 0;
}
