#include <bits/stdc++.h>
using namespace std;
vector<int> edge[100005];
int deg[100005], n, m;
queue<int> que;
int col[100005], used[100005];
int main() {
  scanf("%d%d", &n, &m);
  assert(n == m + 1);
  if (n % 2 == 1) {
    puts("-1");
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    edge[a].push_back(b);
    edge[b].push_back(a);
    deg[a]++;
    deg[b]++;
  }
  int cnt = 0;
  while (1) {
    int zan = 0;
    for (int i = 1; i <= n; i++) {
      if (!used[i]) {
        zan++;
        if (deg[i] == 1) que.push(i);
      }
    }
    if (zan == 2) {
      cnt += 1 - col[que.front()];
      break;
    }
    while (!que.empty()) {
      int q = que.front();
      que.pop();
      used[q] = 1;
      for (int i = 0; i < edge[q].size(); i++) {
        deg[edge[q][i]]--;
        if (!col[q]) {
          col[q] ^= 1;
          col[edge[q][i]] ^= 1;
          cnt++;
        }
      }
    }
  }
  cout << cnt << endl;
}
