#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LINF = 2e16;
const int INF = 1e9;
const int magic = 348;
const double eps = 1e-10;
const double pi = 3.14159265;
inline int getint() {
  char ch;
  int res;
  bool f;
  while (!isdigit(ch = getchar()) && ch != '-') {
  }
  if (ch == '-')
    f = false, res = 0;
  else
    f = true, res = ch - '0';
  while (isdigit(ch = getchar())) res = res * 10 + ch - '0';
  return f ? res : -res;
}
int n, e;
vector<int> v[100048];
bool visited[100048];
int depth[100048], cnt[10004][2], fa[100048];
pair<int, int> cycle;
inline int myabs(int first) { return first >= 0 ? first : -first; }
namespace tree {
inline void dfs(int cur, int father) {
  int i, second;
  cnt[cur][0] = cnt[cur][1] = 0;
  cnt[cur][depth[cur]] = 1;
  for (i = 0; i < int(v[cur].size()); i++) {
    second = v[cur][i];
    if (second != father) {
      depth[second] = depth[cur] ^ 1;
      dfs(second, cur);
      cnt[cur][0] += cnt[second][0];
      cnt[cur][1] += cnt[second][1];
    }
  }
}
inline int solve() {
  int i, first, second;
  depth[1] = 1;
  dfs(1, -1);
  if (cnt[1][0] != cnt[1][1]) return -1;
  int res = 0;
  for (i = 2; i <= n; i++) res += myabs(cnt[i][0] - cnt[i][1]);
  return res;
}
}  // namespace tree
inline void dfs(int cur, int father) {
  int i, second;
  visited[cur] = true;
  fa[cur] = father;
  cnt[cur][0] = cnt[cur][1] = 0;
  cnt[cur][depth[cur]] = 1;
  for (i = 0; i < int(v[cur].size()); i++) {
    second = v[cur][i];
    if (second != father) {
      if (visited[second]) {
        if (cycle.first == 0) cycle = make_pair(second, cur);
        continue;
      }
      depth[second] = depth[cur] ^ 1;
      dfs(second, cur);
      cnt[cur][0] += cnt[second][0];
      cnt[cur][1] += cnt[second][1];
    }
  }
}
namespace even {
vector<int> cir;
bool incir[100048];
inline int solve() {
  if (cnt[1][0] != cnt[1][1]) return -1;
  int cur, i, ans = 0;
  cir.clear();
  memset(incir, false, sizeof(incir));
  for (cur = cycle.second; cur != cycle.first; cur = fa[cur])
    incir[cur] = true, cir.push_back(cnt[cur][1] - cnt[cur][0]);
  cir.push_back(0);
  sort(cir.begin(), cir.end());
  int nm = int(cir.size());
  int coef = cir[nm / 2 - 1];
  for (i = 0; i < int(cir.size()); i++) ans += myabs(cir[i] - coef);
  for (i = 2; i <= n; i++)
    if (!incir[i]) ans += myabs(cnt[i][1] - cnt[i][0]);
  return ans;
}
}  // namespace even
namespace odd {
int w[100048], sz[100048], sum[100048], ans;
inline void dfs(int cur, int father) {
  sz[cur] = (depth[cur] == 0);
  sum[cur] = w[cur];
  int i, second;
  for (i = 0; i < int(v[cur].size()); i++) {
    second = v[cur][i];
    if (second == father || (second == cycle.first && cur == cycle.second) ||
        (second == cycle.second && cur == cycle.first))
      continue;
    dfs(second, cur);
    sz[cur] += sz[second];
    sum[cur] += sum[second];
  }
  if (cur != 1) ans += myabs(sum[cur] - sz[cur]);
}
inline int solve() {
  if (cnt[1][0] % 2 != cnt[1][1] % 2) return -1;
  ans = myabs(cnt[1][0] - cnt[1][1]) / 2;
  int delta = (cnt[1][0] - cnt[1][1]) / 2, i;
  for (i = 1; i <= n; i++) w[i] = depth[i];
  w[cycle.first] += delta;
  w[cycle.second] += delta;
  dfs(1, -1);
  return ans;
}
}  // namespace odd
int main() {
  int i, first, second;
  n = getint();
  e = getint();
  for (i = 1; i <= e; i++)
    first = getint(), second = getint(), v[first].push_back(second),
    v[second].push_back(first);
  if (e == n - 1) {
    printf("%d\n", tree::solve());
    return 0;
  }
  depth[1] = 1;
  cycle = make_pair(0, 0);
  dfs(1, -1);
  if (depth[cycle.first] != depth[cycle.second])
    printf("%d\n", even::solve());
  else
    printf("%d\n", odd::solve());
  return 0;
}
