#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
struct Edge {
  int to, next;
} way[N << 1];
int n, m, tot, num[N], ans, col[N], d[N];
void Build(int a, int b) {
  way[++tot] = (Edge){b, num[a]};
  num[a] = tot;
}
void Init() {
  scanf("%d%d", &n, &m);
  int a, b;
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &a, &b);
    Build(a, b);
    Build(b, a);
    d[a]++;
    d[b]++;
  }
}
void Dfs(int x, int fa) {
  for (int i = num[x]; i; i = way[i].next) {
    int v = way[i].to;
    if (v == fa) continue;
    Dfs(v, x);
  }
  if (!col[x] && fa) col[x] ^= 1, col[fa] ^= 1, ans++;
}
void Solve() {
  if (n == 2) {
    printf("1\n");
    return;
  }
  int root = 1;
  for (int i = 2; i <= n; ++i)
    if (d[i] > 1) root = i;
  if (m == n - 1) {
    ans = 0;
    Dfs(root, 0);
    if (col[root])
      printf("%d\n", ans);
    else
      printf("-1\n");
  } else {
  }
}
int main() {
  Init();
  Solve();
  return 0;
}
