#include <bits/stdc++.h>
using namespace std;
vector<int> vec[100005];
int ans;
int dfs(int v = 0, int p = -1) {
  int now = 0;
  for (int i = 0; i < vec[v].size(); i++) {
    int to = vec[v][i];
    if (to != p) {
      now ^= dfs(to, v);
    }
  }
  if (now == 0) {
    ans++;
    return 1;
  }
  return 0;
}
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);
    a--;
    b--;
    vec[a].push_back(b);
    vec[b].push_back(a);
  }
  if (dfs() == 1)
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
