#include <bits/stdc++.h>
using namespace std;
const int N = (int)1e5 + 100;
vector<int> g[N];
int ans;
int solve(int v, int par) {
  int x = -1;
  for (int to : g[v]) {
    if (to == par) continue;
    x += solve(to, v);
  }
  ans += abs(x);
  return -x;
}
int main(int, char **) {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (m >= n) throw;
  if (solve(0, 0) != 0) {
    printf("-1\n");
    return 0;
  }
  printf("%d\n", ans);
  return 0;
}
