#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int to, next;
} edge[(100000 + 1000) << 1];
int n, m, u[(100000 + 1000)], v[(100000 + 1000)], C[(100000 + 1000)], ans;
int head[(100000 + 1000)], num_edge;
void add(int u, int v) {
  edge[++num_edge].to = v;
  edge[num_edge].next = head[u];
  head[u] = num_edge;
}
void Dfs(int x, int pre) {
  if (C[x] == 1) return;
  for (int i = head[x]; i; i = edge[i].next)
    if (edge[i].to != pre) Dfs(edge[i].to, x);
  if (x == 1) return;
  ans++;
  C[x] ^= 1;
  C[pre] ^= 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &u[i], &v[i]);
    add(u[i], v[i]);
    add(v[i], u[i]);
  }
  Dfs(1, 0);
  if (C[1] == 1)
    printf("%d", ans);
  else
    printf("-1");
}
