#include <bits/stdc++.h>
using namespace std;
const int inf = int(1e9) + int(1e5);
const long long infl = long long(2e18) + long long(1e10);
const int maxn = 100100;
vector<int> g[maxn];
const int ROOT = 0;
int res = 0;
int dfs(int u, int col = 1, int prev = -1) {
  int sum = col;
  for (int v : g[u]) {
    if (v == prev) continue;
    int diff = dfs(v, -col, u);
    sum += diff;
  }
  res += abs(sum);
  return sum;
}
int main() {
  int n, m;
  cin >> n >> m;
  assert(m == n - 1);
  for (int i = 0; i < int(m); ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (dfs(ROOT) != 0) {
    cout << -1 << '\n';
    return 0;
  }
  cout << res << '\n';
}
