#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
int deg[200005], col[200005];
long long ans;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int i, x, y;
  int valid = 1;
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
    deg[x]++;
    deg[y]++;
  }
  queue<int> q;
  if (valid == 0) ans = -1;
  for (i = 1; i <= n; i++)
    if (deg[i] == 1) {
      q.push(i);
      deg[i]--;
    }
  while (!q.empty()) {
    int cur = q.front();
    q.pop();
    int make = 0;
    int cl = 0;
    if (col[cur] == 0) cl = 1;
    int l = v[cur].size();
    for (i = 0; i < l; i++) {
      x = v[cur][i];
      if (deg[x] > 0) {
        deg[x]--;
        make++;
        col[x] += cl;
        col[x] %= 2;
        if (deg[x] == 1) q.push(x);
      }
    }
    ans += cl;
    if (make == 0) {
      if (cl == 1) valid = 0;
    }
  }
  if (valid == 0) ans = -1;
  if (n == 2) ans = 1;
  printf("%lld\n", ans);
  return 0;
}
