#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
int turn(int v, int from, vector<bool>& black, vector<vector<int>>& g) {
  int count = 0;
  for (auto w : g[v]) {
    if (w == from) continue;
    count += turn(w, v, black, g);
  }
  if (!black[v]) {
    if (from != -1) {
      black[from] = !black[from];
      black[v] = true;
      count += 1;
    }
  }
  return count;
}
int main() {
  int n, m;
  vector<vector<int>> g;
  scanf("%d%d", &n, &m);
  assert(n == m + 1);
  g.resize(n);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a -= 1;
    b -= 1;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int s = 0;
  while (g[s].size() > 1) s += 1;
  queue<pair<int, int>> q;
  vector<bool> black(n);
  int ans = turn(0, -1, black, g);
  bool ok = true;
  for (int i = 0; i < n; ++i) ok = ok && (black[i]);
  printf("%d\n", ok ? ans : -1);
  return 0;
}
