#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
int main() {
  long long n, s, t;
  cin >> n >> s >> t;
  long long p[n + 1];
  for (long long i = 1; i <= n; i++) cin >> p[i];
  set<long long> st;
  st.insert(p[s]);
  long long count = 1, ans = p[s];
  while (ans != t) {
    ans = p[ans];
    if (st.find(ans) == st.end())
      st.insert(ans);
    else {
      count = -1;
      break;
    }
    ++count;
  }
  if (s == t) count = 0;
  cout << count << "\n";
}
