#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m, ans;
vector<int> G[N];
int dfs(int u, int v) {
  int res = 1;
  for (int p : G[v])
    if (p != u) res += dfs(v, p);
  res %= 2;
  ans += res;
  return res;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    G[x].push_back(y);
    G[y].push_back(x);
  }
  if (dfs(0, 1))
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}
