#include <bits/stdc++.h>
using namespace std;
vector<int> e[100001];
struct DSU {
  vector<int> p, sz;
  void init(int n) {
    p.resize(n + 1);
    sz.resize(n + 1);
    for (int i = 1; i <= n; i++) sz[p[i] = i] = 1;
  }
  int F(int x) { return x == p[x] ? x : p[x] = F(p[x]); }
  bool U(int x, int y) {
    x = F(x), y = F(y);
    if (x == y) return false;
    if (sz[x] < sz[y]) swap(x, y);
    sz[x] += sz[y];
    p[y] = x;
    return true;
  }
};
int dep[100001], dp[100001];
void dfs(int x, int p) {
  dp[x] = ((dep[x] & 1) ? -1 : 1);
  for (int it : e[x])
    if (it != p) {
      dep[it] = dep[x] + 1;
      dfs(it, x);
      dp[x] += dp[it];
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m, a, b;
  cin >> n >> m;
  DSU D;
  D.init(n);
  for (int i = 1, u, v; i <= m; i++) {
    cin >> u >> v;
    if (D.U(u, v)) {
      e[u].emplace_back(v);
      e[v].emplace_back(u);
    } else
      a = u, b = v;
  }
  if (n == m + 1) {
    dfs(1, 0);
    if (dp[1] != 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) ans += abs(dp[i]);
  cout << ans << endl;
}
