#include <bits/stdc++.h>
int N, M, head[100001], next[200001], to[200001], E, dep[100001], fa[100001],
    fe[100001], v[100001], MU, MV, q[100001];
void BFS() {
  int H = 0, T = 1, u;
  q[1] = 1;
  v[1] = 1;
  while (H < T)
    for (int e = head[u = q[++H]]; e; e = next[e])
      if (e != ((fe[u] + 1) ^ 1) - 1) {
        if (!v[to[e]]) {
          fe[q[++T] = to[e]] = e;
          fa[to[e]] = u;
          v[to[e]] = 1;
          dep[to[e]] = dep[u] + 1;
        } else {
          if (e & 1) {
            MU = u;
            MV = to[e];
          }
        }
      }
}
int main() {
  scanf("%d%d", &N, &M);
  if (N & 1) {
    puts("-1");
    return 0;
  }
  for (int i = 1, u, v; i <= M; i++) {
    scanf("%d%d", &u, &v);
    next[++E] = head[u], to[E] = v, head[u] = E;
    next[++E] = head[v], to[E] = u, head[v] = E;
  }
  BFS();
  if (M == N - 1) {
    static int size[100001][2];
    long long O = 0;
    for (int i = N; i > 1; i--) {
      int u = q[i];
      size[u][0] = (dep[u] & 1) == 0;
      size[u][1] = (dep[u] & 1) == 1;
      for (int e = head[u]; e; e = next[e])
        if (to[e] != fa[u]) {
          size[u][0] += size[to[e]][0];
          size[u][1] += size[to[e]][1];
        }
      O += std::max(size[u][0] - size[u][1], size[u][1] - size[u][0]);
    }
    printf("%lld\n", O);
    return 0;
  }
  assert(0);
  return 0;
}
