#include <bits/stdc++.h>
using namespace std;
int N;
const int maxN = 100100;
vector<int> G[maxN];
void add_edge(int from, int to) {
  G[from].push_back(to);
  G[to].push_back(from);
}
vector<int> bfs(int s) {
  queue<int> q;
  vector<int> dep(maxN);
  bool used[N];
  fill(used, used + N, false);
  for (int i = 0; i < N; i++) {
    dep[i] = -1;
  }
  q.push(s);
  dep[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    used[u] = true;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (!used[v]) {
        q.push(v);
        dep[v] = dep[u] + 1;
      }
    }
  }
  return dep;
}
int main() {
  int u, v;
  cin >> N;
  cin >> u >> v;
  u--;
  v--;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    add_edge(--a, --b);
  }
  int cnt = 0;
  while (u != v) {
    if (G[u].size() == 1) {
      u = G[u][0];
    } else {
      vector<int> depa = bfs(v);
      int now = -1;
      int x = -1;
      for (int i = 0; i < G[u].size(); i++) {
        if (now < depa[G[u][i]]) {
          now = depa[G[u][i]];
          x = G[u][i];
        }
      }
      u = x;
    }
    if (u == v) break;
    cout << u << v << " takahashi" << endl;
    if (G[v].size() == 1) {
      v = G[v][0];
      cnt++;
    } else {
      vector<int> dept = bfs(u);
      int now = maxN;
      int x = -1;
      for (int i = 0; i < G[v].size(); i++) {
        if (now > dept[G[v][i]]) {
          now = dept[G[v][i]];
          x = G[v][i];
        }
      }
      v = x;
      cnt++;
    }
    cout << u << v << " aoki" << endl;
  }
  cout << cnt << endl;
}
