#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1000;
vector<int> G[maxn];
int n, m;
int dp[maxn][2];
bool IsCircle[maxn];
bool vis[maxn];
int res;
void count(int u, int fa) {
  dp[u][0] = 1;
  dp[u][1] = 0;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v != fa && !IsCircle[v]) {
      count(v, u);
      dp[u][0] += dp[v][1];
      dp[u][1] += dp[v][0];
    }
  }
  res += abs(dp[u][0] - dp[u][1]);
}
vector<int> C;
int Stack[maxn];
int cur;
bool found;
void getCircle(int u, int fa) {
  Stack[cur++] = u;
  vis[u] = 1;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v == fa) continue;
    if (!vis[v])
      getCircle(v, u);
    else {
      if (found)
        continue;
      else
        found = true;
      for (int i = cur - 1; i >= 0; --i) {
        IsCircle[Stack[i]] = 1;
        C.push_back(Stack[i]);
      }
    }
  }
  cur--;
}
int cnt[maxn];
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if (m == n - 1) {
    res = 0;
    count(1, -1);
    if (dp[1][0] != dp[1][1])
      puts("-1");
    else
      printf("%d\n", res);
  } else {
    found = false;
    cur = 0;
    memset(vis, 0, sizeof(vis));
    getCircle(1, -1);
    int sz = C.size();
    for (int i = 0; i < sz; ++i) cnt[i] = dp[C[i]][0] - dp[C[i]][1];
    int lft = 0;
    for (int i = 1; i < sz; ++i) lft = cnt[i] - lft;
    if (sz % 2 == 1) {
      int x = abs(cnt[0] - lft) / 2;
      int res = x;
      for (int i = 1; i < sz; ++i) {
        x = cnt[i] - x;
        res += abs(x);
      }
      printf("%d\n", res);
    }
  }
  return 0;
}
