#include <bits/stdc++.h>
using namespace std;
void __print(long long int x) { cerr << x; }
void __print(unsigned x) { cerr << x; }
void __print(unsigned long x) { cerr << x; }
void __print(unsigned long long x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }
template <typename T, typename V>
void __print(const pair<T, V> &x) {
  cerr << '{';
  __print(x.first);
  cerr << ',';
  __print(x.second);
  cerr << '}';
}
template <typename T>
void __print(const T &x) {
  long long int f = 0;
  cerr << '{';
  for (auto &i : x) cerr << (f++ ? "," : ""), __print(i);
  cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v) {
  __print(t);
  if (sizeof...(v)) cerr << ", ";
  _print(v...);
}
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
vector<long long int> v[200005];
long long int ans1[200005], ans2[200005];
long long int bfs1(long long int u) {
  queue<long long int> q;
  q.push(u);
  ans1[u] = 0;
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (auto e : v[x]) {
      if (ans1[e] > ans1[x] + 1) {
        ans1[e] = ans1[x] + 1;
        q.push(e);
      }
    }
  }
}
long long int bfs2(long long int u) {
  queue<long long int> q;
  q.push(u);
  ans2[u] = 0;
  while (!q.empty()) {
    long long int x = q.front();
    q.pop();
    for (auto e : v[x]) {
      if (ans2[e] > ans2[x] + 1) {
        ans2[e] = ans2[x] + 1;
        q.push(e);
      }
    }
  }
}
void solve() {
  long long int n, u, ff;
  cin >> n >> u >> ff;
  if (n == 2) {
    cout << 0 << endl;
    return;
  }
  for (long long int i = 1; i <= n; i++) ans1[i] = 1e18;
  for (long long int i = 1; i <= n; i++) ans2[i] = 1e18;
  for (long long int i = 0; i < n - 1; i++) {
    long long int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  bfs1(u);
  bfs2(ff);
  long long int ans = 0, aa = 1e18;
  for (long long int i = 1; i <= n; i++) {
    if (ans2[i] > ans1[i]) {
      ans = max(ans, ans2[i]);
    }
    if (ans2[i] == ans1[i]) {
      aa = min(aa, ans2[i]);
    }
  }
  if (aa == 1e18) aa = -1;
  cout << max(ans, aa) << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long int t = 1;
  for (long long int tc = 1; tc <= t; tc++) {
    solve();
  }
}
