#include <bits/stdc++.h>
using namespace std;
void debug(stringstream& ds) {
  cerr << endl;
  return;
}
template <typename F, typename... R>
void debug(stringstream& ds, const F& f, const R&... r) {
  string n;
  ds >> n;
  cerr << n << '=' << f << ' ';
  debug(ds, r...);
}
void dbgsplit(string& s) {
  int l = s.length(), n = 0;
  for (int i = 0; i < l; ++i) {
    if (s[i] == '(') ++n;
    if (s[i] == ')') --n;
    if (s[i] == ',' && !n) s[i] = ' ';
  }
}
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;
struct Edge {
  int from, to;
  Edge(int from, int to) : from(from), to(to){};
  Edge() { Edge(0, 0); }
};
struct HeavyLightDecomposition {
  vector<int> index, htop, hchild, par, dep, idtov, topo, sub, heads;
  vector<vector<Edge>> T;
  HeavyLightDecomposition(int n)
      : index(n, -1),
        htop(n),
        hchild(n, -1),
        par(n),
        dep(n),
        idtov(n),
        sub(n),
        T(n) {}
  void calc(int root) {
    queue<int> Q({root});
    par[root] = -1;
    while (!Q.empty()) {
      int curr = Q.front();
      Q.pop();
      topo.push_back(curr);
      for (auto& x : T[curr]) {
        if (x.to != par[curr]) {
          par[x.to] = curr;
          Q.push(x.to);
          dep[x.to] = dep[curr] + 1;
        }
      }
    }
    for (int i = par.size() - 1, max_sub = 0; i >= 0; --i) {
      ++sub[topo[i]];
      if (i > 0) sub[par[topo[i]]] += sub[topo[i]];
      if (i > 0 and i < par.size() - 1)
        if (par[topo[i + 1]] != par[topo[i]]) max_sub = 0;
      if (i > 0 and sub[topo[i]] > max_sub) hchild[par[topo[i]]] = topo[i];
      for (auto& x : T[topo[i]])
        if (x.to != par[topo[i]] and x.to != hchild[topo[i]])
          heads.push_back(x.to);
    }
    heads.push_back(root);
    reverse(heads.begin(), heads.end());
    int id = 0;
    for (int x : heads) {
      for (int i = x; i != -1; i = hchild[i]) {
        index[i] = id++;
        idtov[index[i]] = i;
        htop[i] = x;
      }
    }
  }
  inline bool same(int a, int b) { return htop[a] == htop[b]; }
  int lca(int a, int b) {
    if (index[a] > index[b]) swap(a, b);
    if (same(a, b)) return a;
    return lca(a, par[htop[b]]);
  }
  int dist(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; }
};
struct Problem {
  int size, x, y;
  HeavyLightDecomposition sigma, sugim;
  Problem(int n) : size(n), sigma(n), sugim(n){};
  bool is_sigma_nearer(int i) { return sigma.dist(i, x) < sugim.dist(i, y); }
  int dfs(int par, int cur) {
    if (!is_sigma_nearer(cur)) return -INF;
    if (sigma.T[cur].size() == 1 and sigma.T[cur][0].to == par) {
      return sugim.dist(cur, y);
    }
    int ret = sugim.dist(cur, y);
    for (auto e : sigma.T[cur]) {
      if (e.to != par) {
        if (sugim.dist(cur, e.to) >= 3) return INF;
        ret = max(ret, dfs(cur, e.to));
      }
    }
    return ret;
  }
  void solve() {
    cin >> x >> y;
    --x;
    --y;
    for (int i = 0; i < size - 1; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      sigma.T[a].push_back(Edge(a, b));
      sigma.T[b].push_back(Edge(b, a));
    }
    for (int i = 0; i < size - 1; ++i) {
      int a, b;
      cin >> a >> b;
      --a;
      --b;
      sugim.T[a].push_back(Edge(a, b));
      sugim.T[b].push_back(Edge(b, a));
    }
    sigma.calc(x);
    sugim.calc(y);
    int ans = dfs(-1, x);
    if (ans == INF)
      cout << -1 << "\n";
    else
      cout << ans * 2 << "\n";
  }
};
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  Problem e(n);
  e.solve();
  return 0;
}
