#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int re = 0, flag = 1;
  char ch = getchar();
  while (ch > '9' || ch < '0') {
    if (ch == '-') flag = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    re = (re << 1) + (re << 3) + ch - '0', ch = getchar();
  return re * flag;
}
int n, m, cnt, first[100010], dp[100010];
struct edge {
  int to, next;
} a[200010];
inline void add(int u, int v) {
  a[++cnt] = (edge){v, first[u]};
  first[u] = cnt;
  a[++cnt] = (edge){u, first[v]};
  first[v] = cnt;
}
void dfs(int u, int f, int flag) {
  int i, v;
  dp[u] = flag;
  for (i = first[u]; ~i; i = a[i].next) {
    v = a[i].to;
    if (v == f) continue;
    dfs(v, u, -flag);
    dp[u] += dp[v];
  }
}
int main() {
  memset(first, -1, sizeof(first));
  int i, t1, t2, ans = 0;
  n = read();
  m = read();
  for (i = 1; i <= m; i++) {
    t1 = read();
    t2 = read();
    add(t1, t2);
  }
  if (m == n - 1) {
    dfs(1, 0, 1);
    if (dp[1])
      printf("-1");
    else {
      for (i = 2; i <= n; i++) ans += abs(dp[i]);
      printf("%d\n", ans);
    }
  } else
    printf("-1");
}
