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