#include <bits/stdc++.h>
using namespace std;
const int maxd = 2e5 + 10;
vector<int> G[maxd];
int p, s, ans;
int visp[maxd], viss[maxd];
void dfs(int x, int *vis, int fa) {
  for (int v : G[x]) {
    if (vis[v] || fa == v) continue;
    vis[v] = vis[x] + 1;
    dfs(v, vis, x);
  }
}
bool dfs1(int x, int fa) {
  if (visp[x] > viss[x]) return false;
  if (visp[x] == viss[x]) {
    ans = max(visp[x], ans);
    return false;
  }
  int flag = 0;
  for (int v : G[x]) {
    if (visp[v] || fa == v) continue;
    visp[v] = visp[x] + 1;
    flag += dfs1(v, x);
  }
  if (flag || fa != x) {
    int res = viss[x];
    res -= (viss[x] - visp[x]) % 2;
    ans = max(res, ans);
  }
}
int main() {
  int n, x, y;
  scanf("%d %d %d", &n, &p, &s);
  for (int i = 1; i <= n; i++) {
    scanf("%d %d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  dfs(s, viss, s);
  dfs1(p, p);
  if (n == 2) ans = 0;
  printf("%d", ans - 1);
  return 0;
}
