#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t, *a, x, i;
  scanf("%d %d %d\n", &n, &s, &t);
  a = new int[n];
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  x = s;
  for (i = 0; i < n; i++)
    if (x == t)
      break;
    else
      x = a[x - 1];
  if (x == t)
    printf("%d", i);
  else
    printf("-1");
  return 0;
}
