#include <bits/stdc++.h>
using namespace std;
int get() {
  char ch;
  while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-')
    ;
  if (ch == '-') {
    int s = 0;
    while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
    return -s;
  }
  int s = ch - '0';
  while (ch = getchar(), ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s;
}
const int N = 1e+5 + 5;
const int INF = 1e+9;
int f1[N], f0[N];
int n, m;
struct edge {
  int x, nxt;
} e[N * 2];
int h[N], tot;
int ans;
int cnt[N][2];
int dep[N];
void inse(int x, int y) {
  e[++tot].x = y;
  e[tot].nxt = h[x];
  h[x] = tot;
}
void dfs(int x) {
  cnt[x][dep[x] & 1] = 1;
  for (int p = h[x]; p; p = e[p].nxt)
    if (!dep[e[p].x]) {
      dep[e[p].x] = dep[x] + 1;
      dfs(e[p].x);
      cnt[x][0] += cnt[e[p].x][0];
      cnt[x][1] += cnt[e[p].x][1];
    }
  ans += abs(cnt[x][0] - cnt[x][1]);
}
int main() {
  n = get();
  m = get();
  for (int i = 1; i <= m; i++) {
    int x = get(), y = get();
    inse(x, y);
    inse(y, x);
  }
  dep[1] = 1;
  dfs(1);
  if (cnt[1][0] != cnt[1][1]) ans = -1;
  printf("%d\n", ans);
  return 0;
}
