#include <bits/stdc++.h>
using namespace std;
int dfs(int n, vector<stack<int>> &edge, int p, vector<int> &cnt) {
  int max = 0;
  while (!edge[p].empty()) {
    int nxt = edge[p].top();
    edge[p].pop();
    if (cnt[nxt] < 0) {
      if (max < cnt[p] + 1) max = cnt[p] + 1;
      cnt[nxt] = cnt[p] + 1;
      int tmp = dfs(n, edge, nxt, cnt);
      if (max < tmp) max = tmp;
    }
  }
  return max;
}
int main() {
  int n, pa, pt;
  cin >> n >> pa >> pt;
  vector<stack<int>> edge(n);
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    edge[a - 1].push(b - 1);
    edge[b - 1].push(a - 1);
  }
  vector<int> cnt(n, -1);
  cnt[pa - 1] = 0;
  cout << dfs(n, edge, pa - 1, cnt) << endl;
}
