#include <bits/stdc++.h>
using namespace std;
int n, m;
int f[100005];
vector<int> g[100005];
int read() {
  char c = getchar();
  int x = 0;
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) {
    x = (x << 3) + (x << 1) + c - '0';
    c = getchar();
  }
  return x;
}
void DFS(int u, int pre, int type) {
  f[u] = type;
  for (int i = 0; i < (int)g[u].size(); ++i) {
    int v = g[u][i];
    if (v == pre) continue;
    DFS(v, u, -type);
    f[u] += f[v];
  }
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= m; ++i) {
    int u = read(), v = read();
    g[u].push_back(v);
    g[v].push_back(u);
  }
  DFS(1, 0, 1);
  if (f[1] != 0) {
    puts("-1");
    return 0;
  }
  int res = 0;
  for (int i = 1; i <= n; ++i) res += abs(f[i]);
  printf("%d\n", res);
}
