#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 10;
vector<int> e[MAXN];
int c[MAXN];
int dfs(int u, int f) {
  int ret = 0;
  for (int v : e[u]) {
    if (v == f) continue;
    ret += dfs(v, u);
  }
  if (u != 1 && c[u] == 0) {
    ret++;
    c[f] ^= 1;
  }
  return ret;
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    e[a].push_back(b);
    e[b].push_back(a);
  }
  int ans = dfs(1, 1);
  if (c[1] == 1)
    printf("%d\n", ans);
  else
    puts("-1");
  return 0;
}
