#include <bits/stdc++.h>
using namespace std;
vector<int> g[101010];
long long ans = 0;
int dfs(int v, int prev) {
  int cnt = 0;
  for (auto u : g[v])
    if (u != prev) {
      cnt += dfs(u, v);
    }
  if (cnt % 2 == 0 && v == 0) return -1;
  if (cnt == 0) return 1;
  ans += cnt;
  if (cnt & 1)
    return 0;
  else
    return 1;
}
void solve() {
  int n, m;
  cin >> n >> m;
  assert(m == n - 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  int ok = dfs(0, -1);
  if (ok == -1)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
