#include <bits/stdc++.h>
using namespace std;
const int MAXN = 101010;
const int INF = 1e9;
set<int> E[MAXN];
int col[MAXN];
int jizz() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int s, t;
    scanf("%d%d", &s, &t);
    E[s].insert(t);
    E[t].insert(s);
  }
  int ans = 0;
  static int Q[MAXN];
  int lQ = 0;
  for (int i = 1; i <= n; ++i)
    if (E[i].size() == 1) Q[lQ++] = i;
  for (int i = 0; i < lQ; ++i) {
    int s = Q[i];
    auto it = E[s].begin();
    if (it == E[s].end()) break;
    int p = *it;
    if (not col[s]) col[s] ^= 1, col[p] ^= 1, ans += 1;
    E[p].erase(s);
    if (E[p].size() == 1) Q[lQ++] = p;
  }
  bool allg = true;
  for (int i = 1; i <= n; ++i) allg &= col[i];
  return allg ? ans : -1;
}
int main() {
  printf("%d\n", jizz());
  return 0;
}
