#include <bits/stdc++.h>
using namespace std;
const int LIM = 1e+5 + 100;
vector<vector<int>> g(LIM);
int ans = 0;
int dfs(int v, int p = -1) {
  int res = 1;
  for (int to : g[v]) {
    if (to == p) continue;
    res += dfs(to, v);
  }
  ans += (res - 1);
  return res & 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u;
    --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  int res = dfs(0);
  if (res == 0)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
