#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
constexpr int INF = 1 << 24;
constexpr int LINF = 1LL << 48;
ostream devnull(0);
template <class C>
void vcin(C &c) {
  for (auto &&a : c) {
    cin >> a;
  }
}
template <class C, class D>
void vcin(C &c, D &d) {
  for (auto it1 = c.begin(), it2 = d.begin(); it1 != c.end() && it2 != d.end();
       it1++, it2++) {
    cin >> *it1 >> *it2;
  }
}
template <class C>
void vcout(const C &c, const string delimiter) {
  for (auto it = c.begin(); it != c.end(); it++) {
    if (it != c.begin()) cout << delimiter;
    cout << *it;
  }
}
template <class T = int>
inline T input() {
  T x;
  cin >> x;
  return (x);
}
template <typename T>
inline void chmax(T &x, const T y) {
  if (x < y) x = y;
}
template <typename T>
inline void chmin(T &x, const T y) {
  if (x > y) x = y;
}
inline long long bit(long long n) { return 1LL << n; }
int n, u, v;
map<int, vector<int>> edge;
constexpr int MAX_CNT = 100000;
int dfs2(int t, int a, int cnt);
int dfs1(int t, int a, int cnt = 0) {
  if (t == a) {
    return cnt;
  }
  if (cnt >= MAX_CNT) {
    return INF;
  }
  int ret = -1;
  for (int x : edge[t]) {
    chmax(ret, dfs2(x, a, cnt));
  }
  return ret;
}
int dfs2(int t, int a, int cnt) {
  if (t == a) {
    return cnt;
  }
  if (cnt >= MAX_CNT) {
    return -1;
  }
  int ret = INF;
  for (int x : edge[a]) {
    chmin(ret, dfs1(t, x, cnt + 1));
  }
  return ret;
}
void solve() {
  cin >> n >> u >> v;
  for (auto _ = decltype(n - 1)(0), __len = (n - 1); _ < __len; _ += (1)) {
    int ai, bi;
    cin >> ai >> bi;
    edge[ai].push_back(bi);
    edge[bi].push_back(ai);
  }
  cout << dfs1(u, v) << "\n";
}
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  solve();
  return 0;
}
