#include <bits/stdc++.h>
using namespace std;
template <class S, class T>
istream& operator>>(istream& is, pair<S, T>& p) {
  return is >> p.first >> p.second;
}
const double EPS = 1e-10;
const double PI = acos(-1.0);
const long long MOD = 1e9 + 7;
int N, M;
void dfs(int u, int p, vector<bool>& color, vector<vector<int> >& G, int& res) {
  for (int to : G[u]) {
    if (to == p) continue;
    dfs(to, u, color, G, res);
  }
  if (p >= 0 && !color[u]) {
    color[u] = true;
    color[p] = !color[p];
    ++res;
  }
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  if (N % 2 != 0) {
    cout << -1 << endl;
    return 0;
  }
  if (M != N - 1) return 1;
  vector<vector<int> > G(N);
  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);
  }
  vector<bool> color(N, false);
  int ans = 0;
  dfs(0, -1, color, G, ans);
  if (color[0])
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
