#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const int MOD = 1000000007;
int c[MAX];
int p[MAX];
int b[MAX];
int w[MAX];
vector<int> g[MAX];
void dfs(int st, int par, int col) {
  c[st] = col;
  if (c[st]) {
    w[st] = 1;
  } else {
    b[st] = 1;
  }
  for (int i : g[st]) {
    if (i == par) {
      continue;
    }
    p[i] = st;
    dfs(i, st, 1 - col);
    w[st] += w[i];
    b[st] += b[i];
  }
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (m == n) {
    cout << -2;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(1, -1, 0);
  if (w[1] != b[1]) {
    cout << -1 << endl;
    return 0;
  }
  int ct = 0;
  for (int i = 2; i < n + 1; i++) {
    if (w[i] != b[i]) {
      ct++;
    }
  }
  cout << ct << endl;
}
