#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 1e5 + 5;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
long long po(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
long long res;
int n, m;
int p1, p2;
int num[2], col[maxn], vis[maxn], pre[maxn];
long long st[maxn], en[maxn];
vector<int> edge[maxn];
vector<int> cycle;
void dfs(int x, int fa, int co) {
  vis[x] = 1;
  col[x] = co;
  num[co]++;
  for (int i = 0; i < edge[x].size(); i++) {
    int k = edge[x][i];
    if (vis[k]) continue;
    if (k == fa) continue;
    if (x == p1 && k == p2) continue;
    if (x == p2 && k == p1) continue;
    dfs(k, x, 1 - co);
  }
}
void dfs2(int x, int fa) {
  vis[x] = 1;
  for (int i = 0; i < edge[x].size(); i++) {
    int k = edge[x][i];
    if (vis[k]) continue;
    if (k == fa) continue;
    if (x == p1 && k == p2) continue;
    if (x == p2 && k == p1) continue;
    dfs2(k, x);
    res += abs(st[k] - en[k]);
    st[x] += st[k];
    en[x] += en[k];
  }
  if (col[x]) {
    st[x]++;
  } else {
    en[x]++;
  }
}
void dfs_cycle(int x, int fa) {
  vis[x] = 1;
  pre[x] = fa;
  for (int i = 0; i < edge[x].size(); i++) {
    int k = edge[x][i];
    if (k == fa) continue;
    if (vis[k]) {
      if (p1 == -1) {
        p1 = x;
        p2 = k;
      }
      return;
    }
    dfs_cycle(k, x);
  }
}
void build_cycle() {
  for (int i = p1; i != -1; i = pre[i]) {
    cycle.push_back(i);
    if (i == p2) {
      break;
    }
  }
}
long long cal(long long x) {
  memset(st, 0, sizeof(st));
  memset(en, 0, sizeof(en));
  memset(vis, 0, sizeof(vis));
  st[p1] = x;
  en[p2] = x;
  res = 0;
  dfs2(1, -1);
  return res + x;
}
void solve() {
  scanf("%d%d", &n, &m);
  if (n % 2) {
    puts("-1");
    return;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  p1 = p2 = -1;
  if (m == n - 1) {
    dfs(1, -1, 0);
    if (num[0] == num[1]) {
      memset(vis, 0, sizeof(vis));
      res = 0;
      dfs2(1, -1);
    } else {
      res = -1;
    }
    printf("%lld\n", res);
  } else {
    memset(vis, 0, sizeof(vis));
    dfs(1, -1, 0);
    memset(vis, 0, sizeof(vis));
    dfs_cycle(1, -1);
    build_cycle();
    if (cycle.size() % 2 == 0) {
      long long le = 0, ri = 1e5 + 5;
      while (ri - le > 5) {
        long long mid = (ri + le) / 2;
        long long t1 = cal(mid);
        long long t2 = cal(mid + 1);
        if (t1 < t2) {
          le = mid;
        } else {
          ri = mid;
        }
      }
      long long ans = 0x33ffffffffffffff;
      for (long long i = le; i <= ri; i++) {
        ans = min(ans, cal(i));
      }
      printf("%lld\n", ans);
    } else {
      memset(num, 0, sizeof(num));
      memset(vis, 0, sizeof(vis));
      dfs(p1, -1, 0);
      st[p2] = 0;
      if (num[1] > num[0]) {
        en[p1] = en[p2] = (num[1] - num[0]) / 2;
      } else {
        st[p1] = st[p2] = (num[0] - num[1]) / 2;
      }
      res = 0;
      memset(vis, 0, sizeof(vis));
      dfs2(1, -1);
      printf("%lld", res + abs((num[0] - num[1]) / 2));
    }
  }
}
int main() {
  solve();
  return 0;
}
