#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
struct node {
  int to, nxt;
} e[maxn << 1];
int n, m, tot, head[maxn];
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
void write(int x) {
  print(x);
  puts("");
}
void add(int u, int v) {
  e[++tot].to = v;
  e[tot].nxt = head[u];
  head[u] = tot;
}
namespace lty {
int dep[maxn], ans[maxn], cnt[2];
void dfs(int x, int fa, int Dep) {
  dep[x] = Dep;
  ans[x] = Dep % 2 == 1 ? -1 : 1;
  cnt[Dep % 2]++;
  for (int i = head[x], v = e[i].to; i; i = e[i].nxt, v = e[i].to)
    if (v != fa) dfs(v, x, Dep + 1), ans[x] += ans[v];
}
void solve() {
  dfs(1, 0, 1);
  if (cnt[0] != cnt[1]) {
    puts("-1");
    return;
  }
  int ret = 0;
  for (int i = 1; i <= n; i++) ret += abs(ans[i]);
  write(ret);
}
}  // namespace lty
namespace wyx {
void solve() {}
}  // namespace wyx
int main() {
  n = read();
  m = read();
  for (int i = 1, u, v; i <= m; i++)
    u = read(), v = read(), add(u, v), add(v, u);
  if (m == n - 1)
    lty::solve();
  else
    wyx::solve();
  return 0;
}
