#include <bits/stdc++.h>
using namespace std;
using P = pair<long long, long long>;
using ld = long double;
using ll = long long;
using VI = vector<long long>;
using VVI = vector<vector<long long>>;
using VVC = vector<vector<char>>;
template <class T>
using PQ_inv = priority_queue<T, vector<T>, greater<T>>;
const double pai = 3.1415926535897;
const long long INF = 1000000021;
const ll LINF = 2000000000000000000;
const ll mod = 1000000007;
const long long MAX = 2010000;
const ll MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}
long long COM(long long n, long long k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
ll PER(long long n, long long k) {
  if (n < 0 || k < 0) return 0;
  if (n < k) return fac[n];
  return fac[n] * finv[n - k] % mod;
}
long long modinv(long long a, long long m) {
  long long b = m, u = 1, v = 0;
  while (b) {
    long long t = a / b;
    a -= t * b;
    swap(a, b);
    u -= t * v;
    swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}
long long modpow(long long a, long long n) {
  long long res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}
long long fix_mod(long long& xx) {
  if (xx >= mod * 2 || xx < -mod * 2) {
    xx %= mod;
  }
  if (xx >= mod) xx -= mod;
  return xx;
}
struct edge {
  long long to, cost;
};
edge m_e(long long xx, long long yy) {
  edge ed;
  ed.to = xx;
  ed.cost = yy;
  return ed;
}
long long b_s(vector<long long>& vec, long long xx) {
  return lower_bound(vec.begin(), vec.end(), xx) - vec.begin();
}
template <class T>
void vecout(vector<T>& vec) {
  for (T t : vec) cout << t << " ";
  cout << "\n";
}
template <class T>
void vecout(vector<vector<T>>& vec) {
  for (vector<T> tvec : vec) {
    for (T t : tvec) cout << t << " ";
    cout << "\n";
  }
}
template <class T>
void vecout(vector<pair<T, T>>& vec) {
  for (pair<T, T> p : vec) {
    cout << p.first << " " << p.second << "\n";
  }
}
template <class T>
void vecin(vector<T>& vec) {
  for (long long i = 0; i < (long long)vec.size(); i++) cin >> vec[i];
}
bool chmax(long long& xx, long long yy) {
  if (xx < yy) {
    xx = yy;
    return true;
  }
  return false;
}
bool chmin(long long& xx, long long yy) {
  if (xx > yy) {
    xx = yy;
    return true;
  }
  return false;
}
long long gcd(long long xx, long long yy) {
  long long p = xx;
  long long q = yy;
  if (q > p) swap(p, q);
  while (p % q != 0) {
    p %= q;
    swap(p, q);
  }
  return q;
}
long long lcm(long long xx, long long yy) { return (xx / gcd(xx, yy)) * yy; }
bool prime(long long xx) {
  if (xx <= 1) {
    return 0;
  }
  for (long long i = 2; i * i <= xx; i++) {
    if (xx % i == 0) {
      return 0;
    }
  }
  return 1;
}
signed main() {
  long long n, u, v, a, b, ans = 0;
  cin >> n >> u >> v;
  u--;
  v--;
  VVI tree(n);
  VI ta_flag(n), ao_flag(n);
  for (long long i = 0; i < (long long)(n - 1); i++) {
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }
  queue<long long> ta, ao;
  set<long long> se;
  ta.push(u);
  ao.push(v);
  long long ii = 0;
  while (1) {
    long long a = ta.size();
    if (a == 0) {
      cout << ans - 1 << "\n";
      return 0;
    }
    se.clear();
    for (long long i = 0; i < (long long)(a); i++) {
      long long c = ta.front();
      ta.pop();
      if (ao_flag[c]) {
        continue;
      }
      if (tree[c].size() == 1) {
        if (!ao_flag[tree[c][0]] && !se.count(tree[c][0])) {
          ta.push(tree[c][0]);
          se.insert(tree[c][0]);
        }
        continue;
      }
      for (long long j = 0; j < (long long)(tree[c].size()); j++) {
        if (!ao_flag[tree[c][j]] && !ta_flag[tree[c][j]] &&
            !se.count(tree[c][j])) {
          ta.push(tree[c][j]);
          se.insert(tree[c][j]);
        }
      }
      ta_flag[c] = 1;
    }
    if (!ta.size()) {
      cout << ans - 1 << "\n";
      return 0;
    }
    ans++;
    long long b = ao.size();
    for (long long i = 0; i < (long long)(b); i++) {
      long long c = ao.front();
      ao.pop();
      ao_flag[c] = 1;
      for (long long j = 0; j < (long long)(tree[c].size()); j++) {
        if (!ao_flag[tree[c][j]]) ao.push(tree[c][j]);
      }
    }
    ii++;
    if (ii > n) {
      cout << -1;
      return 0;
    }
  }
}
