#include <bits/stdc++.h>
using namespace std;
void read(vector<long long> &v) {
  for (int i = 0; i < v.size(); i++) cin >> v[i];
}
void print(vector<long long> v) {
  for (int i = 0; i < v.size(); i++) cout << v[i] << " ";
}
long long n, m, a, b, temp;
string str;
set<long long> s;
vector<long long> v[100000 + 1];
long long dist[100000 + 1];
int distao[100000 + 1];
void dfst(int u, int p = -1) {
  if (p != -1) {
    dist[u] = dist[p] + 1;
  }
  for (auto x : v[u]) {
    if (x != p) {
      dfst(x, u);
    }
  }
}
void dfsao(int u, int p = -1) {
  if (p != -1) {
    distao[u] = distao[p] + 1;
  }
  for (auto x : v[u]) {
    if (x != p) {
      dfsao(x, u);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  if (n == 2) {
    cout << 0;
    return 0;
  }
  m = n - 1;
  int t, ao;
  cin >> t >> ao;
  while (m--) {
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  dist[t] = 0;
  distao[ao] = 0;
  dfst(t);
  dfsao(ao);
  long long ans = 0;
  for (int i = 1; i <= n; i++) {
    if (dist[i] < distao[i]) {
      ans = max(ans, dist[i]);
    } else if (dist[i] == distao[i]) {
      if ((dist[i] + distao[i]) == dist[ao]) ans = max(ans, dist[i]);
    }
  }
  cout << ans;
}
