#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const int N = 1234567;
int save_x[N], save_y[N];
vector<int> g[N], g_blue[N];
int d[N], d_blue[N];
int pr[N], pr_blue[N];
void dfs(int v, int pv) {
  if (d[v] >= d_blue[v]) {
    return;
  }
  int sz = g[v].size();
  for (int j = 0; j < sz; j++) {
    int u = g[v][j];
    if (u == pv) {
      continue;
    }
    pr[u] = v;
    d[u] = d[v] + 1;
    dfs(u, v);
  }
}
int n;
void get_d(int start) {
  for (int i = 0; i < n; i++) {
    d[i] = inf;
    pr[i] = -1;
  }
  d[start] = 0;
  pr[start] = start;
  dfs(start, -1);
}
int main() {
  int x, y;
  scanf("%d %d %d", &n, &x, &y);
  x--;
  y--;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d %d", save_x + i, save_y + i);
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int foo = save_x[i];
    int bar = save_y[i];
    g[foo].push_back(bar);
    g[bar].push_back(foo);
  }
  for (int i = 0; i < n; i++) {
    d_blue[i] = inf;
  }
  get_d(y);
  for (int i = 0; i < n; i++) {
    d_blue[i] = d[i];
    g_blue[i] = g[i];
    pr_blue[i] = pr[i];
  }
  for (int i = 0; i < n; i++) {
    g[i].clear();
  }
  for (int i = 0; i < n - 1; i++) {
    int foo, bar;
    foo = save_x[i];
    bar = save_y[i];
    foo--;
    bar--;
    g[foo].push_back(bar);
    g[bar].push_back(foo);
  }
  get_d(x);
  int mx = 0;
  for (int i = 0; i < n; i++) {
    if (d[i] < d_blue[i]) {
      mx = max(mx, 2 * d_blue[i]);
      for (int j = 0; j < (int)g[i].size(); j++) {
        int to = g[i][j];
        if (pr_blue[to] == i || pr_blue[i] == to || pr_blue[pr_blue[to]] == i ||
            pr_blue[pr_blue[i]] == to || pr_blue[i] == pr_blue[to]) {
          continue;
        }
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << mx << endl;
  return 0;
}
