#include <bits/stdc++.h>
using namespace std;
template <typename A, typename B>
inline void chmin(A &a, B b) {
  if (a > b) a = b;
}
template <typename A, typename B>
inline void chmax(A &a, B b) {
  if (a < b) a = b;
}
long long N, M;
vector<long long> G[111111];
long long dp[111111];
long long cost;
long long dfs(long long v, long long p) {
  long long x = 0, y = 0;
  for (auto u : G[v]) {
    if (u == p) continue;
    long long t = dfs(u, v);
    if (t < 0)
      y -= t;
    else
      x += t;
  }
  if (x > y + 1) {
    cost += x - (y + 1);
    return -(x - (y + 1));
  }
  if (x == y + 1) return 0;
  cost += (y + 1) - x;
  return (y + 1) - x;
}
signed main() {
  cin >> N >> M;
  for (long long i = 0; i < (M); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if (N == M) return 0;
  if (dfs(0, -1) == 0)
    cout << cost << endl;
  else
    cout << -1 << endl;
}
