#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXN = 1e5 + 3;
bool f[MAXN];
int n, m, t1, t2, INDEX;
vector<int> g[MAXN];
pair<int, int> p[MAXN];
unordered_set<int> s;
unordered_map<long long, int> dict;
int trans(int x, int y) {
  long long k = 1ll * x * MAXN + y;
  if (dict.count(k))
    return dict[k];
  else
    return dict[k] = ++INDEX;
}
void dfs(int x, int frm) {
  for (auto &i : g[x]) {
    if (i == frm) continue;
    dfs(i, x);
    if (!f[i]) {
      f[i] ^= 1;
      f[x] ^= 1;
      s.insert(trans(i, x));
      p[trans(i, x)] = {i, x};
    }
  }
}
void init() {
  cin >> n >> m;
  if (n == m) {
    cout << "GG" << endl;
    exit(0);
  }
  for (int i = 0; i < (int)(m); i++) {
    cin >> t1 >> t2;
    g[t1].push_back(t2);
    g[t2].push_back(t1);
  }
  dfs(1, 0);
  if (!f[1]) {
    cout << -1 << endl;
    exit(0);
  }
  memset(f, 0, sizeof(f));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  init();
  int ans = 0, tmp = -1;
  bool ok = 0;
  while (s.size()) {
    ok = 0;
    for (auto &i : s) {
      s.erase(tmp);
      tmp = -1;
      if (f[p[i].first] == f[p[i].second]) {
        f[p[i].first] ^= 1;
        f[p[i].second] ^= 1;
        ans++;
        ok = 1;
        tmp = i;
      }
    }
    s.erase(tmp);
    if (!ok) break;
  }
  if (!s.size()) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
