#include <bits/stdc++.h>
using namespace std;
const int inf = 1 << 30;
const long long INF = 1ll << 60;
const double pi = acos(-1);
const double eps = 1e-8;
const long long mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, -1, 0, 1};
int n, m;
vector<vector<int> > g;
vector<int> a, b;
long long f(int v, int p, int d) {
  a[v]++;
  long long res = 0;
  for (auto u : g[v])
    if (u != p) {
      res += f(u, v, d + 1);
      a[v] += b[u];
      b[v] += a[u];
    }
  if (v)
    res += abs(a[v] - b[v]);
  else if (a[v] != b[v])
    res = -1;
  return res;
}
int main() {
  cin >> n >> m;
  assert(m == n - 1);
  g = vector<vector<int> >(n);
  a = b = vector<int>(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);
  }
  cout << f(0, -1, 0) << endl;
}
