#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> g[100010];
int c[100010];
void dfs(int x) {
  for (auto y : g[x]) {
    if (c[y] == 0) {
      c[y] = -c[x];
      dfs(y);
    }
  }
}
long long int ans;
long long int d[100010];
void dfs2(int x, int p) {
  for (auto y : g[x]) {
    if (y == p) continue;
    dfs2(y, x);
  }
  if (g[x].size() == 1) {
    d[x] = 1;
    d[p]++;
  } else if (x != 0) {
    d[p] += d[x] - 1;
    d[x] += d[x] - 1;
  }
}
int main() {
  cin >> n >> m;
  if (n % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  assert(m == n - 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  c[0] = 1;
  dfs(0);
  int s = 0;
  for (int i = 0; i < n; i++) s += c[i];
  if (s != 0) {
    cout << -1 << endl;
    return 0;
  }
  int r = 0;
  for (int i = 0; i < n; i++) {
    if (g[i].size() > 1) {
      r = i;
      break;
    }
  }
  dfs2(r, -1);
  for (int i = 0; i < n; i++) ans += d[i];
  ans /= 2;
  cout << ans << endl;
  return 0;
}
