#include <bits/stdc++.h>
using namespace std;
int n;
int m;
vector<int> v[100002];
long long int ans = 0;
inline pair<int, int> dfs(int b, int val, int pr = -1) {
  int rest = 0;
  int need = 0;
  if (val == 0) {
    need++;
  } else {
    rest++;
  }
  for (int i = 0; i < v[b].size(); i++) {
    int go = v[b][i];
    if (go == pr) continue;
    auto r = dfs(go, val ^ true, b);
    ans += r.first + r.second;
    rest += r.first;
    need += r.second;
  }
  long long int mm = min(rest, need);
  rest -= mm;
  need -= mm;
  return make_pair(rest, need);
}
int main() {
  cin >> n >> m;
  if (m == n) return 1;
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  auto f = dfs(0, 0);
  if (f.first == 0 && f.second == 0) {
    printf("%lld\n", ans);
  } else {
    puts("-1");
  }
  return 0;
}
