#include <bits/stdc++.h>
using namespace std;
int i, j, m, n, p, k, now[100005], size[2][100005], ans, fa[100005], x, y;
vector<int> v[100005];
void dfs(int x) {
  size[now[x]][x]++;
  int i;
  for (i = 0; i < (int)v[x].size(); ++i) {
    int p = v[x][i];
    if (fa[x] == p) continue;
    fa[p] = x;
    now[p] = now[x] ^ 1;
    dfs(p);
    size[0][x] += size[0][p];
    size[1][x] += size[1][p];
  }
  if (x != 1) ans += abs(size[0][x] - size[1][x]);
}
void worka() {
  dfs(1);
  if (size[0][1] == size[1][1])
    cout << ans << endl;
  else
    puts("-1");
}
void workb() {}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; ++i) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  if (m == n - 1)
    worka();
  else
    workb();
}
