#include <bits/stdc++.h>
template <typename T>
bool domax(T &a, T b) {
  return (b > a ? (a = b, true) : false);
}
template <typename T>
bool domin(T &a, T b) {
  return (b < a ? (a = b, true) : false);
}
const int maxn = 100 * 1000 + 5;
int n, m, open[maxn], ans;
std::vector<int> e[maxn];
void go(int i, int j) {
  int op = 1;
  for (int k : e[i])
    if (k != j) {
      go(k, i);
      op -= open[k];
    }
  open[i] = op;
  ans += std::abs(op);
}
int main() {
  scanf("%d%d", &n, &m);
  if (m != n - 1) return 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    e[a].push_back(b);
    e[b].push_back(a);
  }
  go(0, -1);
  if (open[0])
    printf("-1\n");
  else
    printf("%d\n", ans);
}
