#include <bits/stdc++.h>
using namespace std;
const int maxN = 100000 + 233;
int n, m, sz[maxN];
vector<int> G[maxN];
int ans = 0;
int DFS(int u, int fa, int dep) {
  sz[u] = 1;
  int odd = (dep & 1);
  for (int v : G[u])
    if (v != fa) {
      int t = DFS(v, u, dep + 1);
      sz[u] += sz[v];
      odd += t;
      if (t > sz[v] - t)
        ans += t - (sz[v] - t);
      else
        ans += (sz[v] - t) - t;
    }
  return odd;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; ++i) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  if (n == m) assert(false);
  int t = DFS(1, -1, 1);
  if (t * 2 != n)
    printf("-1\n");
  else
    printf("%d\n", ans);
  return 0;
}
