#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];
namespace S1 {
long long num[111111];
long long sz[111111];
long long ans = 0;
void dfs(long long v, long long p, long long c) {
  num[v] = c;
  sz[v] = 1;
  for (auto u : G[v]) {
    if (u == p) continue;
    dfs(u, v, 1 - c);
    num[v] += num[u];
    sz[v] += sz[u];
  }
  ans += abs(sz[v] - num[v] * 2);
}
void solve() {
  dfs(0, -1, 0);
  if (num[0] * 2 != N)
    cout << -1 << endl;
  else
    cout << ans << endl;
}
}  // namespace S1
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 (M == N - 1) {
    S1::solve();
    return 0;
  }
  return 0;
}
