#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int num = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    num = num * 10 + c - '0';
    c = getchar();
  }
  return num * f;
}
struct edge {
  int to, ne;
} e[100005 << 1];
int n, m, tot, head[100005], rt, in[100005], f[100005][2];
bool exi = true;
inline void push(int x, int y) {
  e[++tot].to = y;
  e[tot].ne = head[x];
  head[x] = tot;
  e[++tot].to = x;
  e[tot].ne = head[y];
  head[y] = tot;
}
void dfs(int now, int pre) {
  f[now][0] = 1000000000;
  f[now][1] = 1;
  int mn = 1000000000, cnt = 0, oh = 0;
  bool leaf = true;
  for (int i = head[now]; i; i = e[i].ne) {
    int v = e[i].to;
    if (v == pre) continue;
    dfs(v, now);
    leaf = false;
    if (f[v][1] < f[v][0]) {
      cnt += f[v][1];
      oh++;
      if (f[v][0] != 1000000000) mn = min(mn, f[v][0] - f[v][1]);
    } else if (f[v][0] < f[v][1]) {
      cnt += f[v][0];
      if (f[v][1] != 1000000000) mn = min(mn, f[v][1] - f[v][0]);
    } else if (f[v][0] == 1000000000)
      exi = false;
  }
  if (leaf) {
    return;
  }
  if (oh & 1)
    f[now][0] = cnt, f[now][1] = (mn == 1000000000 ? mn : (cnt + mn + 1));
  else
    f[now][1] = cnt + 1, f[now][0] = ((mn == 1000000000) ? mn : (cnt + mn));
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) push(read(), read());
  if (m == n - 1) {
    for (int i = 1; i <= n; i++)
      if (in[i] == 0) {
        rt = i;
        break;
      }
    dfs(rt, 0);
    if (f[rt][0] == 1000000000) exi = false;
    if (!exi)
      printf("-1");
    else
      printf("%d", f[rt][0]);
    return 0;
  }
}
