#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  return (b < a) ? (a = b, 1) : 0;
}
using ll = long long;
using R = long double;
const R EPS = 1e-9;
inline int sgn(const R &r) { return (r > EPS) - (r < -EPS); }
inline R sq(R x) { return sqrt(max<R>(x, 0.0)); }
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
vector<int> graph[100010];
int ans = 0;
int dfs(int v, int p) {
  int cnt = 0;
  for (auto &v2 : graph[v]) {
    if (v2 == p) continue;
    cnt ^= dfs(v2, v);
  }
  if (cnt == 0) ans++;
  return cnt ^ 1;
}
int main(void) {
  int n, m;
  cin >> n >> m;
  if (m != n - 1) return 0;
  for (int i = int(0); i < int(m); ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  if (dfs(0, -1) == 0)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
