#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> graf[1000007];
long long wyn;
pair<int, int> dfs(int v, int oj) {
  int ret1 = 0;
  int ret2 = 0;
  for (int i = 0; i < graf[v].size(); i++) {
    if (graf[v][i] == oj) continue;
    pair<int, int> bier = dfs(graf[v][i], v);
    ret1 += bier.second;
    ret2 += bier.first;
  }
  ret1++;
  int x = min(ret1, ret2);
  ret1 -= x;
  ret2 -= x;
  wyn += ret1 + ret2;
  return make_pair(ret1, ret2);
}
int main() {
  scanf("%d%d", &n, &m);
  if (n & 1) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= m; i++) {
    int p1, p2;
    scanf("%d%d", &p1, &p2);
    graf[p1].push_back(p2);
    graf[p2].push_back(p1);
  }
  if (dfs(1, 0) != make_pair(0, 0))
    printf("-1\n");
  else
    printf("%lld\n", wyn);
  return 0;
}
