#include <bits/stdc++.h>
using namespace std;
vector<int> g[100010];
long long opt[100010];
long long ans;
bool cyc[100010];
bool vis[100010];
int from[100010];
vector<int> can;
void find_cycle(int x, int par) {
  vis[x] = true;
  from[x] = par;
  for (auto i : g[x]) {
    if (!vis[i]) {
      find_cycle(i, x);
    } else if (i != par && can.empty()) {
      int cur = x;
      while (cur != i) {
        cyc[cur] = true;
        can.push_back(cur);
        cur = from[cur];
      }
      can.push_back(cur);
      cyc[cur] = true;
    }
  }
}
void dfs(int x, int par) {
  opt[x] = 1;
  for (auto i : g[x]) {
    if (i == par || cyc[i]) continue;
    dfs(i, x);
    opt[x] -= opt[i];
  }
  ans += abs(opt[x]);
}
int main(int argc, char const *argv[]) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int p, q;
    scanf("%d %d", &p, &q);
    g[p].push_back(q);
    g[q].push_back(p);
  }
  if (n % 2 == 1) {
    printf("-1\n");
    exit(0);
  }
  if (m == n - 1) {
    dfs(1, 0);
    if (opt[1] == 0) {
      printf("%lld\n", ans);
    } else
      printf("-1\n");
    exit(0);
  }
  find_cycle(1, 0);
  int sz = can.size();
  vector<long long> cost(sz);
  vector<long long> p(sz);
  for (int i = 0; i < sz; i++) {
    dfs(can[i], 0);
    cost[i] = opt[can[i]];
    ans -= abs(cost[i]);
    if (i > 0) {
      if (i & 1)
        p[i] = p[i - 1] - cost[i];
      else
        p[i] = p[i - 1] + cost[i];
    }
  }
  long long start;
  if (sz & 1) {
    long long sum = p[sz - 1] - cost[0];
    if (sum & 1) {
      printf("-1\n");
      exit(0);
    }
    start = sum / 2;
    assert(false);
  } else {
    sort(p.begin(), p.end());
    start = p[sz / 2];
  }
  for (int i = 0; i < sz; i++) {
    ans += abs(start - p[i]);
  }
  printf("%lld\n", ans);
  return 0;
}
