#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
struct edge {
  int nxt, to;
} e[MAXN << 2];
int n, m, head[MAXN], x, y, col[MAXN], tot, res;
void add_edge(int x, int y) {
  e[++tot] = (edge){head[x], y};
  head[x] = tot;
  e[++tot] = (edge){head[y], x};
  head[y] = tot;
}
void dfs(int x, int anc) {
  for (int i = head[x]; i; i = e[i].nxt)
    if (e[i].to != anc) dfs(e[i].to, x);
  if (anc != -1 && !col[x]) col[x] = 1, col[anc] ^= 1, res++;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) scanf("%d%d", &x, &y), add_edge(x, y);
  if (m == n - 1) {
    dfs(1, -1);
    if (col[1])
      printf("%d", res);
    else
      puts("-1");
  }
  return 0;
}
