#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  bool t = false;
  char ch = getchar();
  while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
  if (ch == '-') t = true, ch = getchar();
  while (ch <= '9' && ch >= '0') x = x * 10 + ch - 48, ch = getchar();
  return t ? -x : x;
}
struct Line {
  int v, next;
} e[100100 << 1];
int h[100100], cnt = 1;
inline void Add(int u, int v) {
  e[cnt] = (Line){v, h[u]};
  h[u] = cnt++;
}
int n, m, dep[100100], s[100100], tot, ans, ln;
void dfs(int u, int ff) {
  dep[u] = dep[ff] + 1;
  s[u] = (dep[u] & 1) ? 1 : -1;
  tot += s[u];
  for (int i = h[u]; i; i = e[i].next) {
    int v = e[i].v;
    if (v == ff) continue;
    if (dep[v])
      ln = abs(dep[u] - dep[v]) + 1;
    else
      dfs(v, u), s[u] += s[v];
  }
  ans += abs(s[u]);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    int a = read(), b = read();
    Add(a, b);
    Add(b, a);
  }
  dfs(1, 0);
  if (m == n - 1) {
    if (tot != 0)
      puts("-1");
    else
      printf("%d\n", ans);
    return 0;
  }
  if (ln & 1) {
    if (tot % 2)
      puts("-1");
    else
      printf("%d\n", ans + abs(tot) / 2);
  }
  return 0;
}
