#include <bits/stdc++.h>
namespace Partical {
const int N = 100010, M = N * 2;
int begin[N], next[M], to[M];
bool w[N];
int n, m, e, ans;
void add(int x, int y, bool k = 1) {
  to[++e] = y;
  next[e] = begin[x];
  begin[x] = e;
  if (k) add(y, x, 0);
}
void initialize() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    w[u] ^= 1, w[v] ^= 1;
    add(u, v);
  }
  for (int i = 1; i <= n; i++) w[i] ^= 1;
}
void dfs(int p, int h = 0) {
  for (int i = begin[p], q; i; i = next[i])
    if ((q = to[i]) != h) dfs(q, p), w[p] ^= w[q];
  if (w[p]) ans--;
}
void solve() {
  initialize();
  if (n & 1) {
    printf("-1\n");
    return;
  }
  if (m != n - 1) return;
  ans = n - 1;
  dfs(1);
  printf("%d\n", ans);
}
}  // namespace Partical
int main() {
  Partical::solve();
  return 0;
}
