#include <bits/stdc++.h>
using namespace std;
bool chkmax(int &x, int y) { return x < y ? x = y, true : false; }
bool chkmin(int &x, int y) { return x > y ? x = y, true : false; }
int readint() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, tot, cnt, ncnt;
int v[200005], nxt[200005], h[100005], s1[100005], s2[100005], siz[100005],
    dfn[100005];
void addedge(int x, int y) {
  v[++tot] = y;
  nxt[tot] = h[x];
  h[x] = tot;
  v[++tot] = x;
  nxt[tot] = h[y];
  h[y] = tot;
}
void dfs(int u, int fa) {
  dfn[u] = ++ncnt, siz[u] = 1;
  if (s1[dfn[u]]) cnt++;
  s2[dfn[u]] = s1[dfn[u]] ^ 1;
  for (int p = h[u]; p; p = nxt[p]) {
    if (v[p] == fa) continue;
    s1[ncnt + 1] = s1[dfn[u]] ^ 1;
    dfs(v[p], u);
    siz[u] += siz[v[p]];
  }
}
int main() {
  n = readint();
  m = readint();
  if (n & 1) return printf("-1\n"), 0;
  for (int i = 1; i <= m; i++) addedge(readint(), readint());
  dfs(1, -1);
  if (cnt != n / 2) return printf("-1\n"), 0;
  for (int i = 1; i <= n; i++) s1[i] += s1[i - 1];
  for (int i = 1; i <= n; i++) s2[i] += s2[i - 1];
  long long ans = 0;
  for (int i = 2; i <= n; i++)
    ans += abs(s1[dfn[i] + siz[i] - 1] - s1[dfn[i] - 1] -
               s2[dfn[i] + siz[i] - 1] + s2[dfn[i] - 1]);
  cout << ans << endl;
  return 0;
}
