#include <bits/stdc++.h>
using namespace std;
const int MXN = 100005;
int N, M, fa[MXN], deg[MXN], cnt[MXN], bye[MXN];
vector<int> E[MXN];
int inv[MXN];
void DFS(int u, int f) {
  fa[u] = f;
  for (auto v : E[u]) {
    if (v == f) continue;
    DFS(v, u);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  ;
  cin >> N >> M;
  if (N == 2) {
    cout << 1 << endl;
    return 0;
  }
  int fail = 0;
  if (N & 1) fail = 1;
  for (int i = 0; i < (M); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }
  int r = 0;
  vector<int> leaf;
  for (int i = 0; i < (N); i++) {
    deg[i] = ((int)((E[i]).size()));
    if (deg[i] > 1)
      r = i;
    else {
      leaf.push_back(i);
      inv[i] = 1;
    }
  }
  DFS(r, r);
  int ans = 0;
  while (!leaf.empty()) {
    int x = leaf.back();
    leaf.pop_back();
    if (!bye[x]) {
      ;
      ans++;
    }
    cnt[fa[x]]++;
    bye[x] = 1;
    if (((int)((E[fa[x]]).size())) == 2) {
      int f = fa[x];
      int y = fa[f];
      bye[f] = 1;
      deg[y]--;
      if (deg[y] == 1 and !inv[y]) {
        leaf.push_back(y);
        inv[y] = 1;
      }
    }
  }
  int exist = 0;
  for (int i = 0; i < (N); i++)
    if (!bye[i]) exist++;
  if (exist > 2)
    fail = 1;
  else if (exist == 2)
    ans++;
  if (fail)
    cout << "-1\n";
  else
    cout << ans << endl;
  return 0;
}
