#include <bits/stdc++.h>
namespace particle {
int abs(int x) { return x < 0 ? -x : x; }
const int N = 100100, M = N * 2;
int begin[N], next[M], to[M];
int dep[N];
int n, m, e, ans;
void add(int x, int y, bool k = 1) {
  to[++e] = y;
  next[e] = begin[x];
  begin[x] = e;
  if (k) add(y, x, 0);
}
int dfs(int p, int h = 0) {
  int ret = (dep[p] & 1) ? 1 : -1;
  for (int i = begin[p], q; i; i = next[i])
    if ((q = to[i]) != h) dep[q] = dep[p] + 1, ret += dfs(q, p);
  ans += abs(ret);
  return ret;
}
void initialize() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), add(u, v);
}
void solve() {
  initialize();
  if (m != n - 1) return;
  ans = 0, dep[1] = 1;
  if (dfs(1) == 0)
    printf("%d\n", ans);
  else
    printf("-1\n");
}
}  // namespace particle
int main() {
  particle::solve();
  return 0;
}
