#include <bits/stdc++.h>
using namespace std;
const int inf = 1.01e9;
const double eps = 1e-9;
int n, m;
namespace task1 {
const int N = 1e5 + 10;
int mark[N];
vector<int> v[N];
int d[N][2];
long long res = 0;
void dfs(int x) {
  mark[x] = 1;
  d[x][0] = 1;
  d[x][1] = 0;
  for (int y : v[x]) {
    if (mark[y] == 1) continue;
    dfs(y);
    d[x][0] += d[y][1];
    d[x][1] += d[y][0];
  }
  res += abs(d[x][0] - d[x][1]);
}
void run() {
  for (int i = 0; (i) < (n - 1); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(0);
  if (d[0][0] != d[0][1]) res = -1;
  printf("%lld\n", res);
  exit(0);
}
}  // namespace task1
const int N = 1e5 + 10;
vector<int> v[N];
vector<int> cycle;
int cyc[N];
int mark[N];
int st[N], stc = 0;
int found = 0;
void dfs(int x, int pr = -1) {
  mark[x] = 1;
  st[stc++] = x;
  for (int y : v[x]) {
    if (y == pr) continue;
    if (mark[y] == 1) {
      if (found) continue;
      found = 1;
      for (int i = stc - 1; i >= 0; --i) {
        int z = st[i];
        cycle.push_back(z);
        cyc[z] = 1;
        if (z == y) break;
      }
    } else {
      dfs(y, x);
    }
  }
  stc--;
}
long long res = 0;
int d[N][2];
void calc(int x) {
  mark[x] = 1;
  d[x][0] = 1;
  d[x][1] = 0;
  for (int y : v[x]) {
    if (!cyc[y] && mark[y] == 0) {
      calc(y);
      d[x][0] += d[y][1];
      d[x][1] += d[y][0];
    }
  }
  if (!cyc[x]) res += abs(d[x][0] - d[x][1]);
}
int cnt[N];
long long f(int x, vector<int> &v1, vector<int> &v2) {
  long long r = 0;
  for (int i = 0; (i) < (((int)(v1).size())); ++i) r += abs(v1[i] - x);
  for (int i = 0; (i) < (((int)(v2).size())); ++i) r += abs(v2[i] + x);
  return r;
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == m + 1) {
    task1::run();
    return 0;
  }
  for (int i = 0; (i) < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    --x, --y;
    v[x].push_back(y);
    v[y].push_back(x);
  }
  dfs(0);
  memset(mark, 0, sizeof mark);
  long long val = 0;
  for (int i = 0; (i) < (n); ++i)
    if (cyc[i]) {
      calc(i);
      val += abs(d[i][0] - d[i][1]);
    }
  int cc = ((int)(cycle).size());
  for (int i = 0; (i) < (cc); ++i) {
    cnt[i] = d[cycle[i]][0] - d[cycle[i]][1];
  }
  int ok = val % 2 == 0;
  if (!ok) return 0 * printf("-1\n");
  int a = 1, b = 0;
  for (int i = 1; i < cc; ++i) {
    int a2 = -a;
    int b2 = cnt[i] - b;
    a = a2, b = b2;
  }
  if (a == 1) {
    assert((cnt[0] - b) % 2 == 0);
    int x = (cnt[0] - b) / 2;
    res += abs(x);
    for (int i = 1; i < cc; ++i) {
      x = cnt[i] - x;
      res += abs(x);
    }
    printf("%lld\n", res);
  } else {
  }
  return 0;
}
