#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int read() {
  int x = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  return x;
}
int n, m;
int v[N], ans = 0;
vector<int> e[N];
void solve(int x, int pre) {
  for (auto y : e[x])
    if (y != pre) {
      solve(y, x);
      if (!v[y]) v[x] ^= 1, ans++;
    }
}
int main() {
  n = read(), m = read();
  if (n & 1) return puts("-1"), 0;
  if (m == n) return 0;
  for (int i = 1; i <= n; i++) e[i].clear();
  for (int i = 1; i <= m; i++) {
    int a = read(), b = read();
    e[a].push_back(b);
    e[b].push_back(a);
  }
  memset(v, 0, sizeof v);
  solve(1, 0);
  printf("%d", ans);
  return 0;
}
