#include <bits/stdc++.h>
using namespace std;
vector<int> dist(vector<vector<int>> &adj, int a) {
  int n = adj.size();
  vector<int> ans(n, -1);
  queue<int> q;
  q.push(a);
  ans[a] = 0;
  while (!q.empty()) {
    int f = q.front();
    q.pop();
    for (const int &i : adj[f]) {
      if (ans[i] == -1) {
        ans[i] = ans[f] + 1;
        q.push(i);
      }
    }
  }
  return ans;
}
int main() {
  int n, a, b;
  cin >> n >> a >> b;
  vector<vector<int>> adj(n + 1);
  for (int i = 0; i < n; ++i) {
    int p, q;
    cin >> p >> q;
    adj[p].push_back(q);
    adj[q].push_back(p);
  }
  auto da = dist(adj, a);
  auto db = dist(adj, b);
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (da[i] <= db[i]) ans = max(ans, da[i]);
  }
  cout << ans;
}
