#include <bits/stdc++.h>
using namespace std;
int toint(string s) {
  int n;
  istringstream is(s);
  is >> n;
  return n;
}
string tostring(int n) {
  stringstream is;
  is << n;
  return is.str();
}
long long int modulo(int a, int b, int c) {
  long long x = 1, y = a;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x * y) % c;
    }
    y = (y * y) % c;
    b /= 2;
  }
  return x % c;
}
long long mulmod(long long a, long long b, long long c) {
  long long x = 0, y = a % c;
  while (b > 0) {
    if (b % 2 == 1) {
      x = (x + y) % c;
    }
    y = (y * 2) % c;
    b /= 2;
  }
  return x % c;
}
int query(const vector<int> &tree, int a, int b) {
  if (a == 0) {
    int sum = 0;
    for (; b >= 0; b = (b & (b + 1)) - 1) sum += tree[b];
    return sum;
  } else {
    return query(tree, 0, b) - query(tree, 0, a - 1);
  }
}
void increase(vector<int> &tree, int k, int inc) {
  for (; k < (int)tree.size(); k |= k + 1) tree[k] += inc;
}
int visited[200000];
int p[200000];
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  int i;
  for (i = 1; i <= n; i++) {
    cin >> p[i];
  }
  int ans = 0;
  if (s == t) {
    cout << "0" << endl;
    return 0;
  }
  int tmp = p[s];
  while (visited[tmp] == 0) {
    ans++;
    visited[tmp] = 1;
    if (tmp == t) {
      cout << ans << endl;
      return 0;
    }
    tmp = p[tmp];
  }
  cout << "-1" << endl;
  return 0;
}
