#include <bits/stdc++.h>
using namespace std;
int ab(int x) { return x > 0 ? x : -x; }
vector<int> G[100005];
int f[100005];
int dfs(int x, int fa) {
  f[x] = -1;
  for (int v : G[x])
    if (v != fa) f[x] -= dfs(v, x);
  return f[x];
}
int main() {
  ios::sync_with_stdio(0);
  int n, m;
  cin >> n >> m;
  for (int i = 1, u, v; i <= m; i++)
    cin >> u >> v, G[u].push_back(v), G[v].push_back(u);
  if (!dfs(1, 0)) {
    long long ans = 0;
    for (int i = 1; i <= n; i++) ans += ab(f[i]);
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
