#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 100;
int n, m, dp[N], ans;
int tot, first[N], nxt[N * 2], point[N * 2];
inline void add_edge(int x, int y) {
  tot++;
  nxt[tot] = first[x];
  first[x] = tot;
  point[tot] = y;
}
void dfs(int x, int fa) {
  for (int i = first[x]; i != -1; i = nxt[i]) {
    int u = point[i];
    if (u == fa) continue;
    dfs(u, x);
    if (dp[u] == 0) ans++, dp[x] ^= 1;
  }
}
int main() {
  tot = -1;
  memset(first, -1, sizeof(first));
  memset(nxt, -1, sizeof(nxt));
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    add_edge(u, v);
    add_edge(v, u);
  }
  dfs(1, 1);
  if (dp[1])
    printf("%d\n", ans);
  else
    printf("-1\n");
}
