#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
struct debugger {
  template <typename T>
  debugger& operator,(const T& v) {
    cerr << v << " ";
    return *this;
  }
} dbg;
struct Edge {
  int to, next;
} e[2 * 100000 + 10];
int head[100000 + 10];
void addEdge(int a, int b) {
  static int c = 0;
  e[++c] = (Edge){b, head[a]};
  head[a] = c;
  e[++c] = (Edge){a, head[b]};
  head[b] = c;
}
int n, m;
int f[100000 + 10], g[100000 + 10];
int cnt = 0;
void dfs(int now, int fa) {
  int c1 = 0, c2 = 0;
  for (int i = head[now]; i != 0; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    dfs(v, now);
    if (f[v] > 0) {
      c1 += f[v];
    } else {
      c2 -= f[v];
    }
    g[now] += g[v];
  }
  g[now] += min(c1, c2) + 1;
  f[now] = c2 - c1 + 1;
  if (f[now] < 0) cnt -= f[now];
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    addEdge(a, b);
  }
  dfs(1, 0);
  if (f[1] != 0) {
    puts("-1");
    return 0;
  }
  printf("%d\n", n / 2 + cnt * 2);
  return 0;
}
