#include <bits/stdc++.h>
using namespace std;
const int M = 100100;
int n, m;
vector<int> g[M];
int x[M], y[M];
bool used[M];
void read() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int u, v;
    cin >> u >> v;
    --u, --v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
}
void dfs(int v) {
  used[v] = true;
  int X = 0, Y = 0;
  for (int to : g[v])
    if (!used[to]) {
      dfs(to);
      X += x[to];
      Y += y[to];
    }
  int len = max(2 * Y + 1, 2 * X - 1);
  int W = (len + 1) / 2;
  int B = len / 2;
  assert(W >= X);
  assert(B >= Y);
  y[v] = B - Y;
  x[v] = W - X;
}
void kill() {
  dfs(0);
  if (x[0] != 0 || y[0] != 0) {
    cout << "-1\n";
    return;
  }
  int ans = 0;
  for (int i = 0; i < n; ++i) ans += x[i] + y[i];
  cout << ans << endl;
}
int main() {
  cout.precision(20);
  cout << fixed;
  ios_base::sync_with_stdio(false);
  read();
  kill();
}
