#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct kkk {
  int y, nt;
} e[N << 1];
int st[N], s[N], k[N], cf[N];
int len, top, sum, n, m, S, T;
bool book;
long long ans;
void ins(int x, int y) {
  e[++len].y = y;
  e[len].nt = st[x];
  st[x] = len;
}
void dfs1(int x, int fa) {
  for (int i = st[x]; i; i = e[i].nt) {
    if (e[i].y == fa) continue;
    if (cf[e[i].y]) {
      if (cf[x] == cf[e[i].y]) book = true;
      S = x;
      T = e[i].y;
    } else {
      cf[e[i].y] = -cf[x];
      dfs1(e[i].y, x);
    }
  }
}
void dfs2(int x, int fa) {
  for (int i = st[x]; i; i = e[i].nt) {
    if (e[i].y == fa) continue;
    if ((x == S && e[i].y == T) || (x == T && e[i].y == S)) continue;
    dfs2(e[i].y, x);
    cf[x] += cf[e[i].y];
    k[x] += k[e[i].y];
  }
}
int main() {
  int x, y;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    ins(x, y);
    ins(y, x);
  }
  cf[1] = 1;
  dfs1(1, 1);
  for (int i = 1; i <= n; i++) sum += cf[i];
  if (m ^ n) {
    if (sum) return !puts("0");
  } else if (book) {
    if (sum & 1) return !puts("0");
    ans += abs(sum >> 1);
    cf[S] -= sum >> 1, cf[T] -= sum >> 1;
  } else {
    if (sum)
      return !puts("0");
    else
      k[S] = 1, k[T] = -1;
  }
  dfs2(1, 1);
  for (int i = 1; i <= n; i++)
    if (k[i])
      s[++top] = k[i] * cf[i];
    else
      ans += abs(cf[i]);
  s[++top] = 0;
  sort(s + 1, s + top + 1);
  int mid = s[(top + 1) >> 1];
  for (int i = 1; i <= top; i++) ans += abs(s[i] - mid);
  printf("%lld", ans);
}
