#include <bits/stdc++.h>
using namespace std;
vector<int> adj[100005];
int value[100005];
int sz[100005];
void dfs(int u, int p) {
  for (int v : adj[u]) {
    if (v == p) continue;
    value[v] = value[u] * -1;
    dfs(v, u);
    sz[u] += sz[v];
  }
  sz[u] += value[u];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  value[0] = 1;
  dfs(0, -1);
  long long ans = 0;
  long long balance = 0;
  for (int i = 0; i < n; i++) {
    ans += abs(sz[i]);
    balance += value[i];
  }
  if (balance != 0) ans = -1;
  cout << ans;
}
