#include <bits/stdc++.h>
using namespace std;
struct edge {
  int to, nxxt;
} e[200002];
int n, m, head[200002], cnt = 1, dep[200002], siz[200002], sx, sy, leh,
                        fa[200002], col[200002];
inline void ins(int u, int v) {
  e[cnt].to = v;
  e[cnt].nxxt = head[u];
  head[u] = cnt++;
}
void df5(int te, int la) {
  siz[te] = dep[te];
  for (int i = head[te]; i; i = e[i].nxxt) {
    int j = e[i].to;
    if (j == la) continue;
    dep[j] = -dep[te];
    df5(j, te);
    siz[te] += siz[j];
  }
}
void dfs(int te, int la) {
  siz[te] = col[te];
  for (int i = head[te]; i; i = e[i].nxxt) {
    int j = e[i].to;
    if (j == la) continue;
    if (dep[j] != -1) {
      sx = te, sy = j;
      continue;
    }
    dep[j] = dep[te] + 1;
    fa[j] = te;
    col[j] = -col[te];
    dfs(j, te);
    siz[te] += siz[j];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  if (m == n - 1) {
    for (int i = 1; i < n; i++) {
      int x, y;
      scanf("%d%d", &x, &y);
      ins(x, y);
      ins(y, x);
    }
    dep[1] = 1;
    df5(1, 1);
    int ans = 0;
    for (int i = 2; i <= n; i++) ans += abs(siz[i]);
    if (siz[1]) ans = -1;
    printf("%d\n", ans);
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    ins(x, y);
    ins(y, x);
  }
  memset(dep, -1, sizeof(dep));
  dep[1] = 0;
  fa[1] = 1;
  col[1] = 1;
  dfs(1, 1);
  while (dep[sx] > dep[sy]) sx = fa[sx], leh++;
  while (dep[sy] > dep[sx]) sy = fa[sy], leh++;
  while (sx ^ sy) sx = fa[sx], sy = fa[sy], leh += 2;
  if (leh % 2 == 0) {
    int wt = 0, bl = 0;
    for (int i = 1; i <= n; i++) {
      if (dep[i] & 1)
        wt++;
      else
        bl++;
    }
    if (abs(wt - bl) & 1) {
      puts("-1");
      return 0;
    }
    int ans = 0;
    for (int i = 2; i <= n; i++) ans += abs(siz[i]);
    ans += abs(siz[1]) / 2;
    printf("%d\n", ans);
    return 0;
  }
  while (1)
    ;
}
