#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int stack[20];
template <typename T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (!x) {
    putchar('0');
    return;
  }
  int top = 0;
  while (x) stack[++top] = x % 10, x /= 10;
  while (top) putchar(stack[top--] + '0');
}
template <typename T>
inline void pr1(T x) {
  write(x);
  putchar(' ');
}
template <typename T>
inline void pr2(T x) {
  write(x);
  putchar('\n');
}
const int MAXN = 100005;
int n, m;
namespace solve1 {
struct edge {
  int x, y, next;
} a[2 * MAXN];
int len, last[MAXN];
void ins(int x, int y) {
  len++;
  a[len].x = x;
  a[len].y = y;
  a[len].next = last[x];
  last[x] = len;
}
int cnt, col[MAXN];
int dfs(int x, int fa) {
  for (int k = last[x]; k; k = a[k].next) {
    int y = a[k].y;
    if (y != fa) {
      dfs(y, x);
      if (!col[y]) ++cnt, col[x] ^= 1;
    }
  }
}
int du[MAXN];
void main() {
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    ins(x, y);
    ins(y, x);
    du[x]++;
    du[y]++;
  }
  if (n == 2) {
    puts("1");
    return;
  }
  int rt;
  for (int i = 1; i <= n; i++)
    if (du[i] > 1) {
      rt = i;
      break;
    }
  dfs(rt, 0);
  if (!col[rt])
    puts("-1");
  else
    pr2(cnt);
}
}  // namespace solve1
int main() {
  n = read();
  m = read();
  if (m == n - 1) {
    solve1::main();
    return 0;
  } else
    return 0;
}
