#include <bits/stdc++.h>
using namespace std;
int n, m;
int main() {
  cin >> n >> m;
  vector<int> dg(n, 0);
  vector<pair<int, int> > rb(m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    rb[i] = make_pair(a, b);
    dg[a - 1]++;
    dg[b - 1]++;
  }
  int res = 0;
  int numeven = 0;
  for (int i = 0; i < n; i++) {
    if (dg[i] % 2 == 0) {
      numeven++;
      res += dg[i] - 1;
    } else {
      res += dg[i];
    }
  }
  if (numeven % 2)
    cout << "-1";
  else
    cout << res / 2;
}
