#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
const int Maxn = 100005;
int n, m;
vector<int> neigh[Maxn];
long long dp01[Maxn], dp10[Maxn];
long long res;
void Solve(int v, int p) {
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    if (u == p) continue;
    Solve(u, v);
    dp01[v] += dp01[u];
    dp10[v] += dp10[u];
  }
  long long tk = min(dp01[v], dp10[v]);
  res += 2ll * tk;
  dp01[v] -= tk;
  dp10[v] -= tk;
  if (dp01[v] > 0) {
    res += dp01[v];
    dp10[v] = dp01[v] - 1;
    dp01[v] = 0;
  } else {
    res += dp10[v];
    dp01[v] = dp10[v] + 1;
    dp10[v] = 0;
  }
}
int main() {
  scanf("%d %d", &n, &m);
  assert(m == n - 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    neigh[a].push_back(b);
    neigh[b].push_back(a);
  }
  Solve(1, 0);
  if (dp01[1] == 0 && dp10[1] == 0)
    printf("%lld\n", res);
  else
    printf("-1\n");
  return 0;
}
