#include <bits/stdc++.h>
using namespace std;
inline int read() {
  char c = getchar();
  int num = 0, f = 1;
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') {
    num = num * 10 + c - '0';
    c = getchar();
  }
  return num * f;
}
struct edge {
  int to, ne;
} e[100005 << 1];
int n, m, tot, head[100005], in[100005];
long long ans;
inline void push(int x, int y) {
  e[++tot].to = y;
  e[tot].ne = head[x];
  head[x] = tot;
  e[++tot].to = x;
  e[tot].ne = head[y];
  head[y] = tot;
}
void dfs(int now, int pre) {
  in[now] = 1;
  for (int i = head[now]; i; i = e[i].ne) {
    int v = e[i].to;
    if (v == pre) continue;
    dfs(v, now);
    in[now] -= in[v];
  }
  ans += abs(in[now]);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; i++) push(read(), read());
  if (m == n - 1) {
    dfs(1, 0);
    if (in[1] == 0)
      cout << ans;
    else
      printf("-1");
    return 0;
  }
}
