#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf = 1e9 + 7;
const ll longinf = 1LL << 60;
const ll mod = 1e9 + 7;
using P = pair<int, int>;
struct edge {
  int to;
  int cost;
};
int V;
vector<edge> G[100000];
int d[100000], d2[100000];
void dijkstra(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d, d + V, 1e+9);
  d[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d[e.to] > d[v] + e.cost) {
        d[e.to] = d[v] + e.cost;
        que.push(P(d[e.to], e.to));
      }
    }
  }
}
void dijkstra2(int s) {
  priority_queue<P, vector<P>, greater<P> > que;
  fill(d2, d2 + V, 1e+9);
  d2[s] = 0;
  que.push(P(0, s));
  while (!que.empty()) {
    P p = que.top();
    que.pop();
    int v = p.second;
    if (d2[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); ++i) {
      edge e = G[v][i];
      if (d2[e.to] > d2[v] + e.cost) {
        d2[e.to] = d2[v] + e.cost;
        que.push(P(d2[e.to], e.to));
      }
    }
  }
}
int main() {
  int u, v;
  cin >> V >> u >> v;
  u--;
  v--;
  for (int i = 0; i < V; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(edge{b, 1});
    G[b].push_back(edge{a, 1});
  }
  dijkstra(u);
  dijkstra2(v);
  int ans = d2[u] - 1;
  for (int i = 0; i < V; i++)
    if (d[i] <= d2[i]) ans = max(ans, d2[i] - 1);
  cout << ans;
  return 0;
}
