#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, m, ans;
struct edge {
  int la, b;
} con[N << 1];
int tot, fir[N];
void add(int from, int to) {
  con[++tot] = (edge){fir[from], to};
  fir[from] = tot;
}
int dp[N];
void dfs(int pos, int fa) {
  dp[pos] = 1;
  for (int i = fir[pos]; i; i = con[i].la) {
    if (con[i].b == fa) continue;
    dfs(con[i].b, pos);
    dp[pos] -= dp[con[i].b];
  }
  ans += abs(dp[pos]);
}
int main() {
  int x, y;
  scanf("%d%d", &n, &m);
  assert(m == n - 1);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    add(x, y);
    add(y, x);
  }
  dfs(1, 0);
  if (dp[1] == 0)
    printf("%d\n", ans);
  else
    puts("-1");
  return 0;
}
