#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LINF = 2e16;
const int INF = 1e9;
const int magic = 348;
const double eps = 1e-10;
const double pi = 3.14159265;
inline int getint() {
  char ch;
  int res;
  bool f;
  while (!isdigit(ch = getchar()) && ch != '-') {
  }
  if (ch == '-')
    f = false, res = 0;
  else
    f = true, res = ch - '0';
  while (isdigit(ch = getchar())) res = res * 10 + ch - '0';
  return f ? res : -res;
}
int n, e;
namespace tree {
int depth[100048];
vector<int> v[100048];
int t;
inline void dfs(int cur, int father) {
  int i, second;
  for (i = 0; i < int(v[cur].size()); i++) {
    second = v[cur][i];
    if (second != father) depth[second] = depth[cur] ^ 1, dfs(second, cur);
  }
}
int head[100048], nxt[400048], to[400048], f[400048], cost[400048], tot = 1;
inline void addedge(int s, int t, int cap, int cc) {
  to[++tot] = t;
  nxt[tot] = head[s];
  head[s] = tot;
  f[tot] = cap;
  cost[tot] = cc;
  to[++tot] = s;
  nxt[tot] = head[t];
  head[t] = tot;
  f[tot] = 0;
  cost[tot] = -cc;
}
bool visited[100048];
int D[100048];
int mincost = 0;
int cur[100048];
inline int aug(int first, int maxf) {
  if (first == n + 1) {
    mincost += (-D[0]) * maxf;
    return maxf;
  }
  if (!maxf) return maxf;
  visited[first] = true;
  int second, minf, now, ans = 0;
  for (int &i = cur[first]; i; i = nxt[i]) {
    second = to[i];
    if (!visited[second] && f[i] && D[first] + cost[i] - D[second] == 0) {
      minf = min(maxf - ans, f[i]);
      now = aug(second, minf);
      f[i] -= now;
      f[i ^ 1] += now;
      ans += now;
    }
    if (ans >= maxf) return ans;
  }
  return ans;
}
inline bool relabel() {
  int cur, i, second, d = INF;
  for (cur = 0; cur <= t; cur++)
    if (visited[cur])
      for (i = head[cur]; i; i = nxt[i]) {
        second = to[i];
        if (!visited[second] && f[i]) d = min(d, D[cur] + cost[i] - D[second]);
      }
  if (d >= INF) return false;
  for (cur = 0; cur <= t; cur++)
    if (visited[cur]) D[cur] -= d;
}
inline int solve() {
  int i, j, first, second;
  for (i = 1; i <= e; i++)
    first = getint(), second = getint(), v[first].push_back(second),
    v[second].push_back(first);
  if (n & 1) return -1;
  depth[1] = 1;
  dfs(1, -1);
  int cnt = 0;
  for (i = 1; i <= n; i++) cnt += (depth[i] == 1);
  if (cnt != (n >> 1)) return -1;
  t = n + 1;
  for (i = 1; i <= n; i++)
    if (depth[i] == 1)
      addedge(0, i, 1, 0);
    else
      addedge(i, n + 1, 1, 0);
  for (i = 1; i <= n; i++)
    if (depth[i])
      for (j = 0; j < int(v[i].size()); j++)
        addedge(i, v[i][j], INF, 1), addedge(v[i][j], i, INF, 1);
  do {
    for (i = 0; i <= t; i++) cur[i] = head[i];
    do memset(visited, false, sizeof(visited));
    while (aug(0, INF));
  } while (relabel());
  return mincost;
}
}  // namespace tree
int main() {
  n = getint();
  e = getint();
  if (e == n - 1) {
    printf("%d\n", tree::solve());
    return 0;
  }
  return 0;
}
