#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 20;
int sz[maxn][2], all[2], h[maxn], res;
vector<int> adj[maxn];
void dfs(int v, int p = -1) {
  sz[v][h[v]]++;
  all[h[v]]++;
  for (auto u : adj[v])
    if (u != p) {
      h[u] = 1 - h[v];
      dfs(u, v);
      sz[v][0] += sz[u][0];
      sz[v][1] += sz[u][1];
    }
  res += abs(sz[v][0] - sz[v][1]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  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--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(0);
  if (all[0] != all[1]) return cout << -1 << endl, 0;
  cout << res << endl;
}
