#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
struct node {
  int s, t;
} w1[200100], w2[200100];
int beg[200100], nex[400100], tto[400100], e;
void putin(int s, int t) {
  tto[++e] = t;
  nex[e] = beg[s];
  beg[s] = e;
}
int n;
void clear() {
  e = 1;
  for (int i = 0; i <= n; i++) beg[i] = 0;
}
bool vis[200100];
int f[200100];
int dis[200100];
void getfa(int u) {
  for (int i = beg[u]; i; i = nex[i]) {
    if (tto[i] == f[u]) continue;
    f[tto[i]] = u;
    dis[tto[i]] = dis[u] + 1;
    getfa(tto[i]);
  }
}
int ans;
void dfs(int u, int fa, int dep) {
  if (dis[u] > ans) ans = dis[u];
  if (dep >= dis[u]) return;
  for (int i = beg[u]; i; i = nex[i]) {
    if (tto[i] == fa) continue;
    if (vis[i >> 1]) {
      ans = INF;
      return;
    }
    dfs(tto[i], u, dep + 1);
  }
}
int main() {
  int A, B;
  scanf("%d%d%d", &n, &A, &B);
  if (A == B) {
    printf("0\n");
    return 0;
  }
  clear();
  for (int i = 1; i < n; i++) {
    scanf("%d%d", &w2[i].s, &w2[i].t);
    putin(w2[i].s, w2[i].t);
    putin(w2[i].t, w2[i].s);
  }
  for (int i = 1; i < n; i++) scanf("%d%d", &w1[i].s, &w1[i].t);
  getfa(B);
  clear();
  for (int i = 1; i < n; i++) {
    if (f[w1[i].s] != f[w1[i].t] && f[f[w1[i].s]] != w1[i].t &&
        w1[i].s != f[f[w1[i].t]] && f[w1[i].s] != w1[i].t &&
        f[w1[i].t] != w1[i].s)
      vis[i] = 1;
    else
      vis[i] = 0;
    putin(w1[i].s, w1[i].t);
    putin(w1[i].t, w1[i].s);
  }
  dfs(A, -1, 0);
  if (ans == INF)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
