#include <bits/stdc++.h>
using namespace std;
set<int> gr[114514];
queue<int> q;
int pat[114514], de[114514];
int main() {
  memset(pat, 0, sizeof(pat));
  memset(de, 0, sizeof(de));
  int n, m, a, b, out = 0;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    a--;
    b--;
    de[a]++;
    de[b]++;
    gr[a].insert(b);
    gr[b].insert(a);
  }
  if (n != m + 1) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (de[i] == 1) q.push(i);
  }
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (de[x] < 1) continue;
    set<int>::iterator it = gr[x].begin();
    int y = (*it);
    if (pat[x] < 1) pat[x] = 1 - pat[x], pat[y] = 1 - pat[y], out++;
    gr[y].erase(x);
    de[y]--;
    de[x]--;
    if (de[y] == 1) q.push(y);
  }
  for (int i = 0; i < n; i++) {
    if (pat[i] < 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << out << endl;
}
