#include <bits/stdc++.h>
using namespace std;
string world[8] = {"U", "D", "R", "L", "UL", "UR", "DR", "DL"};
const int rx[8] = {-1, 1, 0, 0, -1, -1, 1, 1};
const int ry[8] = {0, 0, 1, -1, -1, 1, 1, -1};
bool f = true;
vector<int> g[100001];
vector<int> used(100001, 0);
int ans = 0;
void dfs(int v, int p) {
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    dfs(to, v);
  }
  for (int i = 0; i < g[v].size(); i++) {
    int to = g[v][i];
    if (to == p) continue;
    if (used[to] == 0) {
      used[to] = 1;
      used[v] = 1 - used[v];
      ans++;
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  if (n == m) {
    cout << -1;
    return 0;
  }
  int mx = 0, v = 0;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
    if (g[a].size() > mx) {
      mx = g[a].size();
      v = a;
    }
    if (g[b].size() > mx) {
      mx = g[b].size();
      v = b;
    }
  }
  dfs(v, -1);
  for (int i = 0; i < n; i++) {
    if (used[i] == 0) {
      f = false;
    }
  }
  if (!f) {
    cout << -1;
    return 0;
  }
  cout << ans;
  return 0;
}
