#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t, n, i, s, j, p, m, x, y, k, q;
  string s1, s2;
  long long x1, y1;
  cin >> n >> s >> t;
  long long a[n + 1];
  for (long long i = 1; i <= n; i++) cin >> a[i];
  x = s;
  p = 0;
  while (x != t) {
    x = a[x];
    p++;
    if (x == s) {
      p = -1;
      break;
    }
  }
  cout << p;
}
