#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  for (; !isdigit(c); c = getchar())
    if (c == '-') f = -f;
  for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
  x *= f;
}
int n, m, tx, ty, ss, st;
int f[100005], s[100005], t[100005];
bool colour[100005];
vector<int> a[100005];
long long ans;
void work(int pos, int fa) {
  for (unsigned i = 0; i < a[pos].size(); i++)
    if (a[pos][i] != fa) work(a[pos][i], pos);
  s[fa] += s[pos];
  t[fa] += t[pos];
  if (fa != 0) ans += abs(s[pos] - t[pos]);
}
long long solve() {
  ans = 0;
  work(1, 0);
  return ans;
}
void Colour(int pos, int fa) {
  colour[pos] = !colour[fa];
  for (unsigned i = 0; i < a[pos].size(); i++)
    if (a[pos][i] != fa) Colour(a[pos][i], pos);
}
int F(int x) {
  if (f[x] == x)
    return x;
  else
    return f[x] = F(f[x]);
}
int main() {
  read(n), read(m);
  if (n & 1) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) f[i] = i;
  for (int i = 1; i <= m; i++) {
    int x, y;
    read(x), read(y);
    if (F(x) == F(y))
      tx = x, ty = y;
    else {
      f[F(x)] = F(y);
      a[x].push_back(y);
      a[y].push_back(x);
    }
  }
  Colour(1, 0);
  ss = 0, st = 0;
  for (int i = 1; i <= n; i++)
    if (colour[i])
      ss++, s[i] = 1;
    else
      st++, t[i] = 1;
  if (tx == 0 && ty == 0) {
    if (ss == st)
      cout << solve() << endl;
    else
      printf("-1\n");
    return 0;
  }
  return 0;
}
