#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
vector<int> g[100000];
void dfs(vector<int> &d, int u, int v, int l) {
  d[v] = l;
  for (auto t : g[v]) {
    if (t == u) continue;
    dfs(d, v, t, l + 1);
  }
}
int main() {
  int n, u, v, a, b;
  cin >> n >> u >> v;
  u--;
  v--;
  for (int i = 0; i < n - 1; ++i) {
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> d_u(n, 0), d_v(n, 0);
  dfs(d_u, u, u, 0);
  dfs(d_v, v, v, 0);
  int mind = (1 << 30), maxd = 0;
  for (int i = 0; i < n; ++i) {
    if (d_u[i] == d_v[i]) mind = min(mind, d_u[i]);
    if (d_u[i] < d_v[i]) maxd = max(maxd, d_u[i] + (d_v[i] - d_u[i]) / 2);
  }
  if (mind == (1 << 30)) mind = -1;
  cout << max(maxd, mind) << endl;
  return 0;
}
