#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 10;
int n, m, fa[maxn];
vector<int> g[maxn];
namespace tree {
int cnt[maxn][2], ans;
void dfs(int pos) {
  ++cnt[pos][0];
  for (int i = 0; i < g[pos].size(); ++i)
    if (g[pos][i] != fa[pos]) {
      fa[g[pos][i]] = pos;
      dfs(g[pos][i]);
      ans += abs(cnt[g[pos][i]][0] - cnt[g[pos][i]][1]);
      cnt[pos][0] += cnt[g[pos][i]][1];
      cnt[pos][1] += cnt[g[pos][i]][0];
    }
}
int main() {
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1);
  if (cnt[1][0] == cnt[1][1])
    cout << ans << endl;
  else
    cout << -1 << endl;
}
}  // namespace tree
namespace cycle {
int uu, vv, c[maxn];
bool odd;
int findfa(int x) {
  if (fa[x] == x) return x;
  return fa[x] = findfa(fa[x]);
}
void dfs(int pos) {
  for (int i = 0; i < g[pos].size(); ++i)
    if (!c[g[pos][i]]) {
      c[g[pos][i]] = 3 - c[pos];
      dfs(g[pos][i]);
    }
}
void init() {
  for (int i = 1; i <= n; ++i) fa[i] = i;
  for (int i = 1, u, v; i <= m; ++i) {
    cin >> u >> v;
    if (findfa(u) != findfa(v)) {
      fa[findfa(u)] = findfa(v);
      g[u].push_back(v);
      g[v].push_back(u);
    } else
      uu = u, vv = v;
  }
  c[1] = 1;
  dfs(1);
  if (c[uu] == c[vv]) odd = true;
}
}  // namespace cycle
namespace oddcycle {
int cnt[maxn][2], type[maxn], cnt0, cnt1, ans;
void dfs1(int pos) {
  cnt[pos][type[pos]] = 1;
  if (type[pos])
    ++cnt1;
  else
    ++cnt0;
  for (int i = 0; i < g[pos].size(); ++i)
    if (g[pos][i] != fa[pos]) {
      fa[g[pos][i]] = pos;
      type[g[pos][i]] = type[pos] ^ 1;
      dfs1(g[pos][i]);
    }
}
void dfs2(int pos) {
  for (int i = 0; i < g[pos].size(); ++i)
    if (g[pos][i] != fa[pos]) {
      dfs2(g[pos][i]);
      cnt[pos][0] += cnt[g[pos][i]][0];
      cnt[pos][1] += cnt[g[pos][i]][1];
      ans += abs(cnt[g[pos][i]][0] - cnt[g[pos][i]][1]);
    }
}
int main() {
  fa[1] = 0;
  dfs1(1);
  if (cnt0 % 2 != cnt1 % 2) {
    puts("-1");
    return 0;
  }
  cnt[cycle::uu][1] += (cnt0 - cnt1) / 2;
  cnt[cycle::vv][1] += (cnt0 - cnt1) / 2;
  ans = abs((cnt1 - cnt0) / 2);
  dfs2(1);
  printf("%d\n", ans);
}
}  // namespace oddcycle
namespace evencycle {
int cnt[maxn][2], tot[maxn][2], type[maxn], cnt0, cnt1, res, ans = 1e9;
void dfs1(int pos) {
  cnt[pos][type[pos]] = 1;
  if (type[pos])
    ++cnt1;
  else
    ++cnt0;
  for (int i = 0; i < g[pos].size(); ++i)
    if (g[pos][i] != fa[pos]) {
      fa[g[pos][i]] = pos;
      type[g[pos][i]] = type[pos] ^ 1;
      dfs1(g[pos][i]);
    }
}
void dfs2(int pos) {
  tot[pos][0] = cnt[pos][0];
  tot[pos][1] = cnt[pos][1];
  for (int i = 0; i < g[pos].size(); ++i)
    if (g[pos][i] != fa[pos]) {
      dfs2(g[pos][i]);
      tot[pos][0] += tot[g[pos][i]][0];
      tot[pos][1] += tot[g[pos][i]][1];
      res += abs(tot[g[pos][i]][0] - tot[g[pos][i]][1]);
    }
}
int main() {
  fa[1] = 0;
  dfs1(1);
  if (cnt0 != cnt1) {
    puts("-1");
    return 0;
  }
  int l = -n, r = n;
  while (l < r) {
    int midl = floor((2 * l + r) / 3.0), midr = ceil((l + 2 * r) / 3.0), resl,
        resr;
    res = abs(midl);
    cnt[cycle::uu][1] += midl;
    cnt[cycle::vv][1] -= midl;
    dfs2(1);
    cnt[cycle::uu][1] -= midl;
    cnt[cycle::vv][1] += midl;
    resl = res;
    res = abs(midr);
    cnt[cycle::uu][1] += midr;
    cnt[cycle::vv][1] -= midr;
    dfs2(1);
    cnt[cycle::uu][1] -= midr;
    cnt[cycle::vv][1] += midr;
    resr = res;
    if (resl <= resr) {
      r = midr - 1;
      ans = min(ans, resl);
    } else {
      l = midl + 1;
      ans = min(ans, resr);
    }
  }
  printf("%d\n", ans);
}
}  // namespace evencycle
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  if (n > m)
    tree::main();
  else {
    cycle::init();
    if (cycle::odd)
      oddcycle::main();
    else
      evencycle::main();
  }
  return 0;
}
