#include <bits/stdc++.h>
using namespace std;
const int N = 1234567;
vector<int> g[N];
long long ans;
long long dfs(int v, int pr) {
  int sz = g[v].size();
  long long sum = 0;
  for (int j = 0; j < sz; j++) {
    int u = g[v][j];
    if (u == pr) {
      continue;
    }
    long long cur = dfs(u, v);
    sum += cur;
  }
  long long up = 1 - sum;
  ans += (up > 0 ? up : -up);
  return up;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  assert(m == n - 1);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  ans = 0;
  if (dfs(0, -1) != 0) {
    cout << -1 << endl;
  } else {
    cout << ans << endl;
  }
  return 0;
}
