#include <bits/stdc++.h>
using namespace std;
vector<int> E[101000];
int n, m, Dep[101000], G[101000], D[101000];
void DFS(int a, int pp, int dep) {
  int i, x;
  Dep[a] = dep;
  if (dep & 1)
    G[a]++;
  else
    G[a]--;
  for (i = 0; i < E[a].size(); i++) {
    x = E[a][i];
    if (x == pp) continue;
    DFS(x, a, dep + 1);
    D[a] += abs(G[x]) + D[x];
    G[a] += G[x];
  }
}
int main() {
  int i, a, b;
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &a, &b);
    E[a].push_back(b);
    E[b].push_back(a);
  }
  if (m == n - 1) {
    DFS(1, 0, 0);
    if (G[1])
      printf("-1\n");
    else
      printf("%d\n", D[1]);
  }
}
