#include <bits/stdc++.h>
const int MaxN = 100010;
namespace Steaunk {
int n, m, ans, s[MaxN];
int Point[MaxN], Next[MaxN << 1], To[MaxN << 1], q;
void Add(int u, int v) {
  Next[++q] = Point[u];
  Point[u] = q;
  To[q] = v;
  Next[++q] = Point[v];
  Point[v] = q;
  To[q] = u;
}
void dfs(int u, int from) {
  s[u] = 0;
  for (int j = Point[u]; j; j = Next[j])
    if (To[j] != from) dfs(To[j], u);
  if (u != from) {
    s[from] += 1 - s[u];
    ans += (1 - s[u] > 0 ? 1 - s[u] : -(1 - s[u]));
    s[u] = 1;
  }
}
void main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) Point[i] = 0;
  q = 0;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    Add(u, v);
  }
  if (m == n - 1) {
    ans = 0;
    dfs(1, 1);
    if (s[1] != 1)
      puts("-1");
    else
      printf("%d\n", ans);
  } else
    puts("");
}
}  // namespace Steaunk
int main() {
  int T;
  Steaunk::main();
  return 0;
}
