#include <bits/stdc++.h>
using namespace std;
vector<int> v[100005];
long long ans;
int dep[100005];
int dfs(int first, int f) {
  dep[first] = dep[f] + 1;
  int sum = 0;
  for (auto it : v[first]) {
    if (it != f) {
      sum += dfs(it, first);
    }
  }
  if (dep[first] & 1)
    sum++;
  else
    sum--;
  ans += abs(sum);
  return sum;
}
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  if (m == n) return 0;
  for (int i = 0; i < m; i++) {
    int first, second;
    scanf("%d %d", &first, &second);
    v[first].push_back(second);
    v[second].push_back(first);
  }
  if (dfs(1, 0)) {
    printf("-1\n");
  } else
    printf("%lld\n", ans);
}
