#include <bits/stdc++.h>
using namespace std;
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << "\n";
  err(++it, args...);
}
bool visted[100005];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);
  int n, s, t;
  cin >> n >> s >> t;
  vector<int> arr(n + 1);
  for (int i = 1; i <= n; i++) cin >> arr[i];
  if (s == t) {
    cout << 0;
    return 0;
  }
  int cnt = 1;
  int i = s;
  bool flag = 0;
  while (arr[i] != t) {
    if (!visted[i]) {
      visted[i] = 1;
    } else {
      flag = 1;
      break;
    }
    cnt++;
    i = arr[i];
  }
  if (flag)
    cout << -1;
  else
    cout << cnt;
}
