#include <bits/stdc++.h>
using ull = unsigned long long;
using namespace std;
const long long INF = 1ll << 60;
const long long MOD = 1e9 + 7;
template <class T>
bool chmin(T& a, const T& b) {
  if (a > b) {
    a = b;
    return 1;
  } else
    return 0;
}
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  } else
    return 0;
}
void Yes(bool flag = true) {
  if (flag)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}
void No(bool flag = true) { Yes(!flag); }
void YES(bool flag = true) {
  if (flag)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
void NO(bool flag = true) { YES(!flag); }
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T& val) {
  std::fill((T*)array, (T*)(array + N), val);
}
bool dbg = false;
long long N, M;
vector<set<long long>> G;
void solve() {
  long long clr[101010] = {};
  queue<long long> que;
  long long ans = 0;
  for (long long i = 0; i < N; i++) {
    if (G[i].size() == 1) que.push(i);
  }
  while (!que.empty()) {
    long long u = que.front();
    que.pop();
    long long v = *G[u].begin();
    G[u].clear();
    G[v].erase(u);
    if (clr[u] == 0) {
      ans++;
      clr[v] ^= 1;
    }
    if (G[v].size() == 1) {
      que.push(v);
    } else if (G[v].size() == 0) {
      if (clr[v] == 0) ans = -1;
      cout << ans << endl;
      return;
    }
  }
}
signed main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cin >> N >> M;
  G.resize(N);
  for (long long i = 0; i < M; i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].insert(b);
    G[b].insert(a);
  }
  solve();
  return 0;
}
