#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool chkmax(T &x, const T &y) {
  return x < y ? x = y, 1 : 0;
}
struct IO {
  static const int maxn = (1 << 25) + 10;
  char a[maxn], *s, b[maxn], *t;
  void INPUT() {
    s = a;
    t = b;
    a[fread(a, 1, sizeof a, stdin)] = 0;
  }
  void OUTPUT() { fwrite(b, 1, t - b, stdout); }
  operator int() {
    int x = 0;
    while (*s != '-' && (*s < '0' || *s > '9')) {
      ++s;
    }
    bool f = 0;
    if (*s == '-') {
      f = 1;
      ++s;
    }
    while (*s >= '0' && *s <= '9') {
      (x *= 10) += *s - '0';
      ++s;
    }
    if (f) {
      x = -x;
    }
    return x;
  }
  operator long long() {
    long long x = 0;
    while (*s != '-' && (*s < '0' || *s > '9')) {
      ++s;
    }
    bool f = 0;
    if (*s == '-') {
      f = 1;
      ++s;
    }
    while (*s >= '0' && *s <= '9') {
      (x *= 10) += *s - '0';
      ++s;
    }
    if (f) {
      x = -x;
    }
    return x;
  }
  operator char() {
    while (*s <= 32) {
      ++s;
    }
    char ret = *s;
    ++s;
    return ret;
  }
  inline void out(int x) {
    if (!x) {
      *t++ = '0';
      return;
    }
    if (x < 0) {
      *t++ = '-';
      x = -x;
    }
    static char c[20], *i;
    i = c;
    while (x) {
      int y = x / 10;
      *i++ = x - y * 10 + '0';
      x = y;
    }
    while (i != c) {
      *t++ = *--i;
    }
    return;
  }
  inline void out(int x, char C) {
    if (!x) {
      *t++ = '0';
      *t++ = C;
      return;
    }
    if (x < 0) {
      *t++ = '-';
      x = -x;
    }
    static char c[20], *i;
    i = c;
    while (x) {
      int y = x / 10;
      *i++ = x - y * 10 + '0';
      x = y;
    }
    while (i != c) {
      *t++ = *--i;
    }
    *t++ = C;
    return;
  }
  inline void out(long long x) {
    if (!x) {
      *t++ = '0';
      return;
    }
    if (x < 0) {
      *t++ = '-';
      x = -x;
    }
    static char c[20], *i;
    i = c;
    while (x) {
      long long y = x / 10;
      *i++ = x - y * 10 + '0';
      x = y;
    }
    while (i != c) {
      *t++ = *--i;
    }
    return;
  }
  inline void out(long long x, char C) {
    if (!x) {
      *t++ = '0';
      *t++ = C;
      return;
    }
    if (x < 0) {
      *t++ = '-';
      x = -x;
    }
    static char c[20], *i;
    i = c;
    while (x) {
      long long y = x / 10;
      *i++ = x - y * 10 + '0';
      x = y;
    }
    while (i != c) {
      *t++ = *--i;
    }
    *t++ = C;
    return;
  }
  inline void out(char c) {
    *t++ = c;
    return;
  }
  inline void out(char *s) {
    while (*s >= ' ') {
      *t++ = *s++;
    }
    return;
  }
} io;
void Main();
int main(int argc, char *argv[]) {
  io.INPUT();
  Main();
  io.OUTPUT();
  return 0;
}
const int maxn = 1e5 + 100;
int n, m;
namespace tree {
vector<int> g[maxn];
int ans;
int dfs(int u = 1, int p = 0) {
  int x = -1;
  for (int v : g[u]) {
    if (v != p) {
      x += dfs(v, u);
    }
  }
  ans += abs(x);
  return -x;
}
void solve() {
  for (int i = 0, i_end_ = (m); i < i_end_; ++i) {
    int u = io, v = io;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  io.out(dfs() ? -1 : ans, '\n');
  return;
}
}  // namespace tree
void Main() {
  n = io, m = io;
  if (n & 1) {
    io.out(-1, '\n');
    return;
  }
  if (m == n - 1) {
    tree::solve();
    return;
  }
}
