#include <bits/stdc++.h>
using namespace std;
template <class T>
void read(T &res) {
  res = 0;
  T f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    res = res * 10 + c - '0';
    c = getchar();
  }
  res *= f;
}
template <class T>
void out(T x) {
  if (x < 0) {
    x = -x;
    putchar('-');
  }
  if (x >= 10) {
    out(x / 10);
  }
  putchar('0' + x % 10);
}
struct node {
  int to, next;
} E[100005 * 2];
int N, head[100005], sumE, M;
long long dp[100005][2], ans;
void add(int u, int v) {
  E[++sumE].to = v;
  E[sumE].next = head[u];
  head[u] = sumE;
}
void dfs(int u, int fa) {
  dp[u][0] = 1;
  for (int i = head[u]; i; i = E[i].next) {
    int v = E[i].to;
    if (v != fa) {
      dfs(v, u);
      ans += (dp[v][0] + dp[v][1]) * 1;
      dp[u][0] += dp[v][1];
      dp[u][1] += dp[v][0];
    }
  }
  int t = min(dp[u][0], dp[u][1]);
  dp[u][0] -= t;
  dp[u][1] -= t;
}
void Solve() {
  read(N);
  read(M);
  int a, b;
  for (int i = 1; i <= M; ++i) {
    read(a);
    read(b);
    add(a, b);
    add(b, a);
  }
  if (N & 1) {
    puts("-1");
    return;
  }
  if (M == N - 1) {
    dfs(1, 0);
    if (dp[1][0] || dp[1][1]) {
      puts("-1");
      return;
    }
    out(ans);
    putchar('\n');
  }
}
int main() {
  Solve();
  return 0;
}
