#include <bits/stdc++.h>
using namespace std;
const bool white = false, black = true;
bool cycle;
int Node, Line;
int topo[10100], Count = 0;
enum stat { W = 1, B, Fin };
stat color[10100];
vector<vector<int> > VEC;
queue<int> Q;
void topofunc() {
  int now;
  while (!Q.empty()) {
    now = Q.front();
    Q.pop();
    for (int &next : VEC[now])
      if (color[next] != Fin && color[now] == W) {
        color[next] = (color[next] == W) ? B : W;
        color[now] = Fin;
        if (--topo[next] == 1) Q.push(next);
      }
  }
}
int main() {
  int i, j, k;
  cin >> Node >> Line;
  cycle = (Node == Line);
  if (Node - 1 == Line) {
    if (Node % 2 == 0) cout << Line;
    if (Node % 2 == 1) cout << -1;
    return 0;
  }
  VEC.resize(Node + 1);
  for (i = 1; i <= Line; i++) {
    scanf("%d%d", &j, &k);
    VEC[j].push_back(k);
    topo[j]++;
    VEC[k].push_back(j);
    topo[k]++;
  }
  for (i = 1; i <= Node; i++) {
    color[i] = W;
    if (topo[i] == 1) Q.push(i);
  }
  topofunc();
  for (i = 1; i <= Node; i++)
    if (color[i] != W) Count++;
  cout << Count;
}
