#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
double PI = 3.1415926535897932384626433832795;
long double EPS = 1e-12;
const int MAXN = 100100;
const int ROOT = 333;
int n, m;
int was[MAXN], qq[MAXN], en, st;
int col[MAXN];
int deg[MAXN];
vector<vector<int> > gr;
int ans = 0;
void bfs(int u) {
  for (int i = 0; i < gr[u].size(); ++i) {
    int to = gr[u][i];
    if (was[to]) continue;
    deg[to]--;
    if (deg[to] == 1) {
      qq[en++] = to;
      was[to] = 1;
    }
    if (!col[u]) {
      ans++;
      col[u] = 1;
      col[to] ^= 1;
    }
  }
}
void solve() {
  scanf("%d %d", &n, &m);
  gr.resize(n);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--, v--;
    gr[u].push_back(v);
    gr[v].push_back(u);
    deg[u]++;
    deg[v]++;
  }
  for (int i = 1; i < n; ++i) {
    if (deg[i] == 1) {
      qq[en++] = i;
      was[i] = 1;
    }
  }
  while (st != en) {
    bfs(qq[st++]);
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < gr[i].size(); ++j) {
      int to = gr[i][j];
      if (!col[to] && !col[i]) {
        col[to] = 1;
        col[i] = 1;
        ans++;
      }
    }
  }
  int add = 0;
  for (int i = 0; i < n; ++i) {
    if (!col[i]) add++;
  }
  if (add)
    printf("-1");
  else
    printf("%d\n", ans);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  srand(1313);
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
