#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};
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> g[n];
  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);
  }
  bool f = true;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (g[i].size() % 2 == 0) f = false;
    ans += g[i].size();
  }
  if (!f) {
    cout << -1;
    return 0;
  }
  ans -= m;
  cout << ans;
  return 0;
}
