#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, u, v;
  cin >> n >> u >> v;
  vector<vector<int>> t(n + 1, vector<int>(0));
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    t[a].push_back(b), t[b].push_back(a);
  }
  int res = 0;
  vector<bool> r(n + 1, true);
  r[v] = false;
  queue<pair<int, pair<int, bool>>> s;
  s.push({u, {0, true}});
  s.push({v, {1, false}});
  while (!s.empty()) {
    int p = s.front().first, q = s.front().second.first;
    bool b = s.front().second.second;
    s.pop();
    if (b == true) {
      if (r[p] == true)
        for (auto& i : t[p])
          if (r[i] == true) s.push({i, {0, true}});
      if (s.front().second.second == false && s.back().second.second == false)
        break;
    } else {
      r[p] = true;
      for (auto& i : t[p]) s.push({i, {q + 1, false}}), r[i] = false;
      res = q;
    }
  }
  cout << res;
  return 0;
}
