#include <bits/stdc++.h>
using namespace std;
int n, m, ret;
vector<int> edge[100005];
pair<int, int> dfs(int v, int u, int col) {
  int sum = 0, par = (col ? 1 : -1);
  for (int i = 0; i < edge[v].size(); i++) {
    if (edge[v][i] == u) continue;
    pair<int, int> p = dfs(edge[v][i], v, 1 - col);
    int add = p.first;
    sum += add;
    ret += add;
    par += p.second;
  }
  if (sum % 2 == 1 && par == 0) {
    return make_pair(0, 0);
  } else if (sum % 2 == 1) {
    return make_pair(2, par);
  } else {
    return make_pair(1, par);
  }
}
int main() {
  cin >> n >> m;
  assert(n == m + 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  pair<int, int> p = dfs(1, -1, 0);
  if (p.second) {
    cout << -1 << endl;
    return 0;
  }
  cout << ret << endl;
}
