#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, s, t;
  scanf("%d%d%d", &n, &s, &t);
  vector<int> sh;
  set<int> visited;
  for (int i = 0; i < n; ++i) {
    int inp;
    scanf("%d", &inp);
    sh.push_back(inp);
  }
  while (visited.find(s) == visited.end() && s != t) {
    visited.insert(s);
    s = sh[s - 1];
    if (s == t) break;
  }
  if (s == t) {
    printf("%d", visited.size());
  } else {
    printf("-1");
  }
}
