#include <bits/stdc++.h>
using namespace std;
long long read() {
  char ch = getchar();
  long long x = 0, ff = 1;
  while (ch < '0' || ch > '9') {
    if (ch == '-') ff = -ff;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') x = x * 10 + ch - '0', ch = getchar();
  return x * ff;
}
void write(long long aa) {
  if (aa < 0) putchar('-'), aa = -aa;
  if (aa > 9) write(aa / 10);
  putchar(aa % 10 + '0');
  return;
}
long long n, m, ans;
long long F[100005];
long long tot, head[100005], nx[200005], to[200005];
void jia(long long aa, long long bb) {
  tot++;
  nx[tot] = head[aa];
  to[tot] = bb;
  head[aa] = tot;
  return;
}
void dfs(long long rt, long long fa) {
  long long sum = 1;
  for (long long i = head[rt]; i; i = nx[i]) {
    long long yy = to[i];
    if (yy == fa) continue;
    dfs(yy, rt);
    sum += F[yy];
  }
  F[rt] = abs(sum);
  if (sum >= 0) F[rt] = -F[rt];
  ans += abs(F[rt]);
  return;
}
int main() {
  n = read();
  m = read();
  if (n == m) {
    puts("-1");
    return 0;
  }
  for (long long i = 1; i <= m; ++i) {
    long long x = read(), y = read();
    jia(x, y);
    jia(y, x);
  }
  dfs(1, 1);
  if (F[1] == 0)
    write(ans);
  else
    puts("-1");
  return 0;
}
