#include <bits/stdc++.h>
using namespace std;
int n, s, t, ans, a[100001];
void solve() {
  int cnt = 0;
  if (s == t)
    cout << 0;
  else {
    while (1) {
      if (a[s] == t) {
        cout << ans + 1;
        break;
      }
      if (a[a[s]] == s) {
        cout << -1;
        break;
      } else {
        s = a[s];
        ans++;
      }
      cnt++;
      if (cnt >= 100002) {
        cout << -1;
        return;
      }
    }
  }
}
void read() {
  cin >> n >> s >> t;
  for (int i = 1; i <= n; i++) cin >> a[i];
}
int main() {
  read();
  solve();
}
