#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long bigmod(long long base, long long power, long long mod) {
  if (power == 0)
    return 1;
  else if (power % 2 == 1) {
    long long value1 = base % mod;
    long long value2 = (bigmod(base, power - 1, mod)) % mod;
    return (value1 * value2) % mod;
  } else {
    long long value1 = (bigmod(base, power / 2, mod)) % mod;
    return (value1 * value1) % mod;
  }
}
const int mx = 1e5 + 10;
int arr[mx];
bool vis[mx];
int main() {
  int n, s, t;
  scanf("%d %d %d", &n, &s, &t);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  if (s == t and arr[s] == arr[t])
    printf("0");
  else if (arr[s] == s || arr[t] == t)
    printf("-1");
  else {
    int i = s, count = 0, j = 0;
    bool check = false;
    while (true) {
      if (j == n || vis[i] == true) break;
      if (vis[i] == false) {
        if (i == t) {
          check = true;
          printf("%d", count);
          break;
        }
        count++;
        vis[i] = true;
        i = arr[i];
        j++;
      }
    }
    if (!check) printf("-1");
  }
}
