#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  t = 1;
  while (t--) {
    int n, s, e;
    cin >> n >> s >> e;
    int arr[n + 1];
    for (int i = 1; i <= n; i++) {
      cin >> arr[i];
    }
    vector<int> v;
    int s2 = s;
    for (int i = 0; i < n; i++) {
      int j = arr[s2];
      v.push_back(j);
      s2 = j;
    }
    bool ab = false;
    int pos = -1;
    for (int i = 0; i < n; i++) {
      if (s == e) {
        pos = 0;
        break;
      } else {
        if (v[i] == e) {
          pos = i + 1;
          break;
        }
      }
    }
    cout << pos << endl;
  }
}
