#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
struct Edge {
  int to, next;
} edge[N * 2];
int head[N], num;
void add_edge(int a, int b) { edge[++num] = (Edge){b, head[a]}, head[a] = num; }
int h[N * 2], dep[N], fa[N], d[N];
bool val[N];
int p, q;
void dfs(int x) {
  dep[x] = dep[fa[x]] + 1;
  if (dep[x] & 1)
    d[x] += 1;
  else
    d[x] -= 1;
  for (int i = head[x]; i; i = edge[i].next)
    if (edge[i].to != fa[x] &&
        (!((x == p && edge[i].to == q) || (x == q && edge[i].to == p)))) {
      fa[edge[i].to] = x;
      dfs(edge[i].to);
      d[x] += d[edge[i].to];
    }
}
bool vis0[N];
void dfs0(int x, int fff) {
  vis0[x] = true;
  for (int i = head[x]; i; i = edge[i].next)
    if (edge[i].to != fff) {
      if (vis0[edge[i].to])
        p = x, q = edge[i].to;
      else
        dfs0(edge[i].to, x);
    }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n - 1; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add_edge(x, y);
    add_edge(y, x);
  }
  if (n - 1 == m) {
    dfs(1);
    if (d[1] != 0)
      printf("-1\n");
    else {
      int ans = 0;
      for (int i = 1; i <= n; i++) ans += abs(d[i]);
      printf("%d\n", ans);
    }
  } else {
    scanf("%d%d", &p, &q);
    add_edge(p, q);
    add_edge(q, p);
    dfs0(1, 0);
    dfs(p);
    if (!((dep[q] - dep[p]) & 1)) {
      int tmp = d[p];
      if (abs(tmp) & 1)
        printf("-1\n");
      else {
        for (int i = 1; i <= n; i++) d[i] = 0;
        d[p] -= tmp / 2, d[q] -= tmp / 2;
        dfs(p);
        int ans = abs(tmp) / 2;
        for (int i = 1; i <= n; i++) ans += abs(d[i]);
        printf("%d\n", ans);
      }
    }
  }
  return 0;
}
