#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> edge[100005];
int sum[100005][2];
void dfs(int v, int u, int col) {
  sum[v][0] = col;
  sum[v][1] = 1 - col;
  for (int i = 0; i < edge[v].size(); i++) {
    if (edge[v][i] == u) continue;
    dfs(edge[v][i], v, 1 - col);
    for (int j = 0; j < 2; j++) sum[v][j] += sum[edge[v][i]][j];
  }
}
void sol_tree() {
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }
  dfs(1, -1, 0);
  if (sum[1][0] % 2 != sum[1][1] % 2) {
    cout << -1 << endl;
    exit(0);
  }
  long long ans = 0;
  for (int i = 2; i <= n; i++) ans += abs(sum[i][0] - sum[i][1]);
  cout << ans << endl;
}
void sol_namori() {}
int main() {
  cin >> n >> m;
  if (m == n - 1)
    sol_tree();
  else
    sol_namori();
}
