#include <bits/stdc++.h>
using namespace std;
const double PI = 3.1415926535897932384626433;
void solve() {
  int n;
  cin >> n;
  ;
  int pray;
  cin >> pray;
  ;
  pray--;
  int hunter;
  cin >> hunter;
  ;
  hunter--;
  vector<vector<int> > tree(n);
  for (int i = 0; i < n - 1; i++) {
    int u;
    cin >> u;
    ;
    u--;
    int v;
    cin >> v;
    ;
    v--;
    tree[u].push_back(v);
    tree[v].push_back(u);
  }
  function<int(int, int)> dfs1 = [&](int node, int parent) {
    if (node == pray) return 1;
    for (int chl : tree[node]) {
      if (chl != parent) {
        int level = dfs1(chl, node);
        if (level > 0) return level + 1;
      }
    }
    return -1;
  };
  function<int(int, int)> dfs2 = [&](int node, int parent) {
    int ans = 0;
    for (int chl : tree[node])
      if (chl != parent) ans = max(ans, dfs2(chl, node));
    return ans + 1;
  };
  int ans = -1;
  for (int chl : tree[hunter]) {
    int level = dfs1(chl, hunter);
    if (level > 0) {
      ans = dfs2(chl, hunter);
      ans--;
      break;
    }
  }
  cout << ans << endl;
}
int main() {
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);
  solve();
}
