#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int i, j, k, n, m, En, x, y, X, Y, ch, ff, ans;
int h[N], f[N], dp[N];
struct edge {
  int s, n;
} E[N << 1];
void R(int &x) {
  ff = x = 0;
  ch = getchar();
  while (ch < '0' || '9' < ch) {
    if (ch == '-') ff = 1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  if (ff) x = -x;
}
void E_add(int x, int y) {
  E[++En].s = y;
  E[En].n = h[x];
  h[x] = En;
  E[++En].s = x;
  E[En].n = h[y];
  h[y] = En;
}
void dfs(int x, int F) {
  dp[x] = dp[F] + 1;
  if (dp[x] & 1)
    f[x] = 1;
  else
    f[x] = -1;
  for (int k = h[x]; k; k = E[k].n)
    if (E[k].s != F) {
      if (dp[E[k].s])
        X = x, Y = E[k].s;
      else {
        dfs(E[k].s, x);
        f[x] += f[E[k].s];
      }
    }
}
int main() {
  R(n);
  R(m);
  for (i = 1; i <= m; i++) {
    R(x);
    R(y);
    E_add(x, y);
  }
  dfs(1, 0);
  if (n == m) {
  }
  if (f[1]) return puts("-1"), 0;
  for (i = 1; i <= n; i++) ans += abs(f[i]);
  printf("%d\n", ans);
}
