#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int a[N], b[N], d[N], cnt[N][2];
vector<int> G[N];
void dfs(int x, int p = 0) {
  cnt[x][0] = cnt[x][1] = 0;
  d[x] = d[p] + 1;
  cnt[x][d[x] & 1]++;
  for (int u : G[x]) {
    if (u == p) continue;
    dfs(u, x);
    cnt[x][0] += cnt[u][0];
    cnt[x][1] += cnt[u][1];
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    a[i] = u, b[i] = v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  if (m == n - 1) {
    dfs(1);
    if (cnt[1][0] != cnt[1][1]) return 0 * puts("-1");
    int ans = 0;
    for (int i = 0; i < m; ++i) {
      if (d[a[i]] > d[b[i]]) swap(a[i], b[i]);
      ans += abs(cnt[b[i]][0] - cnt[b[i]][1]);
    }
    printf("%d\n", ans);
    return 0;
  }
}
