#include <bits/stdc++.h>
using namespace std;
const int MINF = -1e9;
int main() {
  int n, m;
  cin >> n >> m;
  if (n - 1 != m) return 0;
  if (n % 2) return puts("-1") * 0;
  set<int> v[n];
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    v[a].insert(b);
    v[b].insert(a);
  }
  queue<int> que;
  for (int i = 0; i < n; i++) {
    if (v[i].size() == 1) que.push(i);
  }
  int an = 0;
  bool bl[n];
  fill(bl, bl + n, false);
  while (!que.empty()) {
    int from = que.front();
    que.pop();
    int to = *v[from].begin();
    if (bl[from] == false) bl[from] = true, bl[to] ^= true, an++;
    v[from].clear();
    v[to].erase(from);
    if (v[to].size() == 1) que.push(to);
  }
  cout << an << endl;
}
