#include <bits/stdc++.h>
using namespace std;
const int N = 500009;
const int mod = 1000000007;
long long int n, U, V, x, y;
long long int dixu[N];
long long int dixv[N];
vector<long long int> v[N];
void dfs(long long int x, long long int p) {
  for (auto &it : v[x]) {
    if (it == p) continue;
    dixu[it] = dixu[x] + 1;
    dfs(it, x);
  }
}
void dfs1(long long int x, long long int p) {
  for (auto &it : v[x]) {
    if (it == p) continue;
    dixv[it] = dixv[x] + 1;
    dfs1(it, x);
  }
}
void pre() {}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  pre();
  cin >> n >> U >> V;
  for (long long int i = 0; i < (n - 1); i++) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dixu[U] = 0;
  dfs(U, -1);
  dixv[V] = 0;
  dfs1(V, -1);
  long long int ans = -1;
  for (long long int i = 1; i <= n; i++) {
    long long int a = dixu[i], b = dixv[i];
    if (a <= b) {
      if ((b - a) % 2 == 0) {
        ans = max(ans, b);
      }
    } else {
    }
  }
  for (long long int i = 1; i <= n; i++) {
    long long int a = dixu[i], b = dixv[i];
    if (a == b) continue;
    if (a > b) {
    } else {
      if ((b - a) % 2 == 1) {
        ans = max(ans, b - 1);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
