#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 (v == par[u]) continue;
    if (par[v]) {
      climb(v);
      climb(par[v]);
      return;
    } else {
      par[v] = u;
      find_cyc(v);
    }
  }
}
long long ans = 0;
inline long long dfs(int u) {
  long long ret = 0;
  for (auto v : edge[u]) {
    if (v != par[u] && !cyc[v]) ret += dfs(v);
  }
  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 <= (m); ++i) {
    cin >> u >> v;
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  par[1] = -1;
  find_cyc(1);
  if (n != m) {
    if (dfs(1)) ans = -1;
    cout << ans << '\n';
    return 0;
  }
  return 0;
}
