#include <bits/stdc++.h>
using namespace std;
int n, m;
int deg[100055];
bool color[100055];
vector<int> g[100055];
bool used[100055];
int main() {
  scanf("%d %d", &n, &m);
  int x, y;
  while (m--) {
    scanf("%d %d", &x, &y);
    x--, y--;
    g[x].push_back(y);
    g[y].push_back(x);
    deg[x]++;
    deg[y]++;
  }
  set<pair<int, int> > s;
  for (int i = 0; i < n; i++) s.insert(pair<int, int>(deg[i], i));
  int res = 0;
  while (!s.empty()) {
    int u = s.begin()->second;
    s.erase(s.begin());
    used[u] = true;
    if (deg[u] == 0) continue;
    bool flip = false;
    if (!color[u]) {
      flip = true;
      res++;
      color[u] = true;
    }
    for (auto v : g[u]) {
      if (used[v]) continue;
      s.erase(pair<int, int>(deg[v], v));
      deg[v]--;
      s.insert(pair<int, int>(deg[v], v));
      if (flip) color[v] ^= true;
    }
  }
  for (int i = 0; i < n; i++) {
    if (!color[i]) {
      puts("-1");
      return 0;
    }
  }
  printf("%d\n", res);
  return 0;
}
