#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
vector<int> g[N];
vector<int> vis(N, 0);
vector<int> d(N, -1), f(N, -1);
int c = 0;
void dfs(int u) {
  vis[u] = 1;
  d[u] = ++c;
  for (int v : g[u]) {
    if (!vis[v]) {
      dfs(v);
    }
  }
  f[u] = c;
}
int main() {
  int n, t, a;
  cin >> n >> t >> a;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(a);
  vector<int> p(n + 1, INT_MAX);
  p[a] = 0;
  priority_queue<int> q;
  q.push(a);
  while (!q.empty()) {
    int u = q.top();
    q.pop();
    for (int i = 0; i < (int)g[u].size(); i++) {
      int v = g[u][i];
      if (p[u] + 1 < p[v]) {
        p[v] = p[u] + 1;
        q.push(v);
      }
    }
  }
  int _max = -1;
  for (int u = 1; u <= n; u++) {
    if (d[u] == f[u]) {
      _max = max(_max, p[u]);
    }
  }
  cout << _max - 1 << endl;
}
