#include <bits/stdc++.h>
using namespace std;
int N, M;
int res;
vector<unordered_set<int> > G;
int state[100010];
int main() {
  ios::sync_with_stdio(false);
  int a, b;
  cin >> N >> M;
  G.resize(N + 1);
  for (int i = 1; i <= N; i++) state[i] = 1;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    G[a].insert(b);
    G[b].insert(a);
  }
  queue<int> X;
  for (int i = 1; i <= N; i++) {
    if (G[i].size() == 1) X.push(i);
  }
  res = 0;
  while (X.size() > 0) {
    a = X.front();
    X.pop();
    if (G[a].size() == 0) {
      if (state[a] % 2 == 1) {
        cout << -1 << endl;
        return 0;
      }
      continue;
    }
    unordered_set<int>::iterator it;
    it = G[a].begin();
    b = *it;
    if (state[a] % 2 == 1) {
      state[a] = 0;
      state[b]++;
      res++;
    }
    G[a].erase(b);
    G[b].erase(a);
    if (G[b].size() == 1) X.push(b);
  }
  for (int i = 1; i <= N; i++) {
    if (state[i] % 2) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << res << endl;
}
