#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  cin >> n >> s >> t;
  s--;
  t--;
  vector<int> next(n);
  for (int i = 0; i < n; i++) cin >> next[i], next[i]--;
  vector<bool> vis(n);
  int count = 0;
  for (int i = s; i != t; i = next[i]) {
    if (vis[i]) {
      cout << -1;
      return 0;
    }
    vis[i] = true;
    count++;
  }
  cout << count;
}
