#include <bits/stdc++.h>
using namespace std;
int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') s = s * 10 + ch - '0', ch = getchar();
  return f * s;
}
vector<int> e[100010];
int n, m, col[100010], d[100010], s[100010];
void add(int x, int y) {
  e[x].push_back(y);
  e[y].push_back(x);
  d[x]++;
  d[y]++;
}
int buc[2], a[100010];
void dfs(int x, int fr) {
  col[x] = !col[fr];
  buc[col[x]]++;
  a[x] = col[x] ? 1 : -1;
  for (int i = 0; i < e[x].size(); i++)
    if (e[x][i] != fr) dfs(e[x][i], x);
}
void dfs2(int x, int fr) {
  s[x] = a[x];
  for (int i = 0, y; i < e[x].size(); i++)
    if ((y = e[x][i]) != fr) dfs2(y, x), s[x] += s[y];
}
long long tree() {
  dfs(1, 0);
  if (buc[0] != buc[1]) return -1;
  long long ans = 0;
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) ans += abs(s[i]);
  return ans;
}
vector<int> val;
queue<int> q;
bool vis[100010];
long long even() {
  int x = q.front();
  q.pop();
  int y;
  for (vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++)
    if (vis[(*it)]) {
      y = *it;
      e[x].erase(it);
      break;
    }
  for (vector<int>::iterator it = e[y].begin(); it != e[y].end(); it++)
    if ((*it) == x) {
      e[y].erase(it);
      break;
    }
  dfs(1, 0);
  if (buc[0] != buc[1]) return -1;
  dfs2(x, 0);
  val.push_back(s[y]);
  while (!q.empty()) {
    int w = q.front();
    q.pop();
    if (w == y) continue;
    val.push_back(s[w]);
  }
  sort(val.begin(), val.end());
  int k = val[val.size() + 1 >> 1];
  a[x] += k;
  a[y] -= k;
  dfs2(1, 0);
  long long ans = 0;
  for (int i = 1; i <= n; i++) ans += abs(s[i]);
  return ans;
}
long long odd() {
  int x = q.front();
  q.pop();
  int y;
  for (vector<int>::iterator it = e[x].begin(); it != e[x].end(); it++)
    if (vis[(*it)]) {
      y = *it;
      e[x].erase(it);
      break;
    }
  for (vector<int>::iterator it = e[y].begin(); it != e[y].end(); it++)
    if ((*it) == x) {
      e[y].erase(it);
      break;
    }
  dfs(1, 0);
  int sum = abs(buc[1] - buc[0]);
  if (sum & 1) return -1;
  if (buc[0] > buc[1])
    for (int i = 1; i <= n; i++) a[i] = -a[i], s[i] = -s[i];
  int val = sum >> 1;
  long long ans = val;
  a[x] -= val;
  a[y] -= val;
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) ans += abs(s[i]);
  return ans;
}
int from[100010];
int getloop() {
  for (int i = 1; i <= n; i++)
    if (d[i] == 1) q.push(i);
  int qwq = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    qwq++;
    vis[x] = 1;
    for (int i = 0; i < e[x].size(); i++) {
      if (e[x][i] != from[x] && d[e[x][i]] > 0) d[e[x][i]]--, from[e[x][i]] = x;
      if (e[x][i] != from[x] && d[e[x][i]] == 1) q.push(e[x][i]);
    }
  }
  for (int i = 1; i <= n; i++)
    if (!vis[i])
      q.push(i), vis[i] = 1;
    else
      vis[i] = 0;
  return (n - qwq) & 1;
}
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    add(x, y);
  }
  if (m == n - 1) return printf("%lld\n", tree()), 0;
  if (getloop())
    return printf("%lld\n", odd()), 0;
  else
    return printf("%lld\n", even()), 0;
  return 0;
}
