#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
const int MAXN = 1e5 + 10;
vector<int> edge[MAXN], cycle;
int par[MAXN], cyc[MAXN];
inline void climb(int u) {
  while (~u) {
    cyc[u] ^= 1;
    u = par[u];
  }
}
inline void find_cyc(int u) {
  static bool flag = false;
  if (flag) return;
  for (auto v : edge[u]) {
    if (flag) return;
    if (v == par[u]) continue;
    if (par[v]) {
      climb(u);
      climb(v);
      flag = true;
      return;
    } else {
      par[v] = u;
      find_cyc(v);
    }
  }
}
long long ans = 0;
inline long long dfs(int u, int fa) {
  long long ret = 0;
  for (auto v : edge[u]) {
    if (v != fa && !cyc[v]) ret += dfs(v, u);
  }
  ans += abs(ret - 1);
  return 1 - ret;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL), cout.tie(NULL);
  int n, m, u, v;
  cin >> n >> m;
  for (register int i = (1); i <= int(m); ++i) {
    cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  if (n != m) {
    if (dfs(1, -1)) ans = -1;
    cout << ans << '\n';
    return 0;
  }
  par[1] = -1;
  find_cyc(1);
  for (register int i = (1); i <= int(n); ++i) {
    if (~par[i])
      if (cyc[i] && !cyc[par[i]]) {
        cyc[par[i]] = 1;
        break;
      }
  }
  for (register int i = (1); i <= int(n); ++i) {
    if (cyc[i]) cycle.push_back(i);
  }
  vector<long long> cv;
  if (cycle.size() & 1) {
    for (;;)
      ;
    for (auto u : cycle) {
      cv.push_back(dfs(u, -1));
      ans -= abs(cv.back());
    }
    long long tot = 0, mul = 1;
    for (auto v : cv) {
      tot += mul * v;
      mul = -mul;
    }
    if (tot & 1)
      ans = -1;
    else {
      long long tmp = tot / 2;
      for (auto v : cv) {
        ans += abs(v);
        tmp = v - tmp;
      }
    }
    cout << ans << '\n';
  } else {
    int u = cycle[0];
    for (register int i = (0); i <= int(edge[u].size() - 1); ++i) {
      int v = edge[u][i];
      if (cyc[v]) {
        edge[u].erase(edge[u].begin() + i);
        for (register int j = (0); j <= int(edge[v].size() - 1); ++j) {
          if (edge[v][j] == u) {
            edge[v].erase(edge[v].begin() + j);
            break;
          }
        }
        break;
      }
    }
    ans = 0;
    memset(cyc, 0, sizeof(cyc));
    if (dfs(1, -1)) ans = -1;
    cout << ans << '\n';
  }
  return 0;
}
