#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const long long mod = 1e9 + 7;
const int inf = 50000;
int ans, n, m, cnt, first[maxn], a[maxn], d[maxn], x, y, cut;
bool vis[maxn];
struct Edge {
  int to, next;
} e[maxn << 1];
void add(int u, int v) {
  e[++cnt] = (Edge){v, first[u]};
  first[u] = cnt;
}
void Dfs1(int u, int fa) {
  vis[u] = 1;
  d[u] = d[fa] + 1;
  a[u] = (d[u] & 1) ? 1 : -1;
  for (int i = first[u]; i; i = e[i].next) {
    int v = e[i].to;
    if (v == fa) continue;
    if (vis[v]) {
      cut = i;
      x = u, y = v;
    }
    Dfs1(v, u);
    a[u] += a[v];
  }
}
int main() {
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int u, v;
    cin >> u >> v;
    add(u, v);
    add(v, u);
  }
  if (m == n - 1) {
    Dfs1(1, 0);
    if (a[1] != 0)
      cout << -1 << endl;
    else {
      for (int i = 1; i <= n; i++) ans += abs(a[i]);
      cout << ans << endl;
    }
  }
}
