#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
struct edge {
  int v;
  edge *next;
} pool[3 * N], *h[N];
int n, m, top = -1;
int size[N], ans;
int p[N], col[N], vis[N];
int circle, S, T;
inline void addedge(int u, int v) {
  edge *tmp = &pool[++top];
  tmp->v = v;
  tmp->next = h[u];
  h[u] = tmp;
}
void dfs_1(int u) {
  size[u] = col[u] = -col[p[u]];
  vis[u] = true;
  for (edge *tmp = h[u]; tmp; tmp = tmp->next) {
    int v = tmp->v;
    if (p[u] == v) continue;
    if (vis[v]) {
      S = u;
      T = v;
      circle = abs(col[u] + col[v]) / 2;
      continue;
    }
    p[v] = u;
    dfs_1(v);
    size[u] += size[v];
  }
  ans += abs(size[u]);
}
void dfs_2(int u) {
  vis[u] = true;
  size[u] = col[u];
  for (edge *tmp = h[u]; tmp; tmp = tmp->next) {
    int v = tmp->v;
    if (vis[v]) continue;
    dfs_2(v);
    size[u] += size[v];
  }
  ans += abs(size[u]);
}
void init() {
  int x, y;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    addedge(x, y);
    addedge(y, x);
  }
  col[0] = -1;
  dfs_1(1);
  if (m == n - 1) {
    if (size[1]) return (void)printf("-1\n");
  } else if (circle == 0) {
    if (size[1]) return (void)printf("-1\n");
    ans = 0;
    for (int i = 1; i <= n; i++) vis[i] = false;
    vis[p[S]] = true;
    vis[T] = true;
    dfs_2(S);
    ans -= abs(size[S]);
    dfs_2(T);
  } else {
    if (abs(size[1]) & 1) return (void)printf("-1\n");
    col[S] -= size[1] / 2;
    col[T] -= size[1] / 2;
    ans = abs(size[1]) / 2;
    for (int i = 1; i <= n; i++) vis[i] = false;
    dfs_2(1);
  }
  printf("%d\n", ans);
}
int main() {
  cin >> n >> m;
  init();
  return 0;
}
