#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:102400000,102400000")
#pragma warning(disable : 4996)
using namespace std;
const int maxn = 1e5 + 5;
const long long mod = 1e9 + 7;
const double PI = acos(-1.0);
long long po(long long a, long long b, long long mod) {
  long long res = 1;
  a %= mod;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) {
  if (a == 0) {
    return b;
  } else {
    return gcd(b % a, a);
  }
}
int res;
int n, m;
int p1, p2;
int num[2], col[maxn], vis[maxn];
int st[maxn], en[maxn];
vector<int> edge[maxn];
void dfs(int x, int fa, int co) {
  vis[x] = 1;
  col[x] = co;
  num[co]++;
  for (int i = 0; i < edge[x].size(); i++) {
    int k = edge[x][i];
    if (vis[k]) continue;
    if (k == fa) continue;
    if (x == p1 || k == p2) continue;
    if (x == p2 || k == p1) continue;
    dfs(k, x, 1 - co);
  }
}
void dfs2(int x, int fa) {
  vis[x] = 1;
  for (int i = 0; i < edge[x].size(); i++) {
    int k = edge[x][i];
    if (vis[k]) continue;
    if (k == fa) continue;
    if (x == p1 || k == p2) continue;
    if (x == p2 || k == p1) continue;
    dfs2(k, x);
    res += abs(st[k] - en[k]);
    st[x] += st[k];
    en[x] += en[k];
  }
  if (col[x]) {
    st[x]++;
  } else {
    en[x]++;
  }
}
void solve() {
  scanf("%d%d", &n, &m);
  if (n % 2) {
    puts("-1");
    return;
  }
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  p1 = p2 = -1;
  if (m == n - 1) {
    dfs(1, -1, 0);
    if (num[0] == num[1]) {
      memset(vis, 0, sizeof(vis));
      res = 0;
      dfs2(1, -1);
    } else {
      res = -1;
    }
  } else {
  }
  printf("%d\n", res);
}
int main() {
  solve();
  return 0;
}
