#include <bits/stdc++.h>
using namespace std;
const long long inf = 0x3f3f3f3f3f3f3f3fll;
template <class class_name>
void print_vector(vector<class_name> vec) {
  cout << endl;
  for (auto item : vec) {
    cout << item << " ";
  }
  cout << endl;
}
void solve() {}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, s, t;
  cin >> n >> s >> t;
  vector<long long> p(n + 1);
  for (long long i = 1; i < n + 1; i++) {
    cin >> p[i];
  }
  if (s == t) {
    cout << 0;
    return 0;
  } else if (p[s] == s || p[t] == t) {
    cout << -1;
    return 0;
  } else {
    long long flag = 1, pos = s, cnt = 0;
    while (pos != t) {
      pos = p[pos];
      cnt++;
      if (pos == s) {
        flag = 0;
        break;
      }
    }
    if (flag == 0) {
      cout << -1;
    } else {
      cout << cnt;
    }
  }
  return 0;
}
