#include <bits/stdc++.h>
using namespace std;
vector<int> w[120001];
int n, m, s, d[120001], f[120001], type, uid, vid;
long long cnt[120001], sz[120001];
long long dfs(int u, int p, int dep) {
  if (dep & 1) s++, cnt[u]++;
  sz[u] = 1;
  d[u] = dep;
  f[u] = p;
  for (int v : w[u])
    if (v != p && !sz[v])
      cnt[u] += dfs(v, u, dep + 1), sz[u] += sz[v];
    else if (v != p && d[u] > d[v])
      type = (d[u] & 1) ^ (d[v] & 1), uid = u, vid = v;
  return cnt[u];
}
inline void add(int u, long long k) {
  while (u) cnt[u] += k, u = f[u];
}
signed main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    w[u].push_back(v);
    w[v].push_back(u);
  }
  dfs(1, 0, 0);
  if (m == n - 1) {
    if (s * 2 != n) {
      puts("-1");
      return 0;
    }
    long long ans = 0;
    for (int i = 2; i <= n; i++) ans += abs(sz[i] - 2 * cnt[i]);
    printf("%lld\n", ans);
  } else if (type) {
    abort();
  } else {
    if ((n - s - s) % 2) {
      puts("-1");
      return 0;
    }
    long long k = (n - s - s) / 2;
    add(uid, k);
    add(vid, k);
    for (int i = 2; i <= n; i++) k += abs(sz[i] - 2 * cnt[i]);
    printf("%lld\n", k);
  }
  return 0;
}
