#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 100;
int n, m;
vector<int> edg[MAXN];
bool vis[MAXN], col[MAXN], onc[MAXN];
int ccnt[MAXN][2];
vector<int> cir;
int U, V;
int find_circle(int x, int fa) {
  vis[x] = true;
  for (int i = 0; i < edg[x].size(); i++)
    if (edg[x][i] != fa) {
      int y = edg[x][i], tmp = vis[y] ? y : find_circle(y, x);
      if (tmp) onc[x] = true, cir.push_back(x);
      return x == tmp ? 0 : tmp;
    }
  return 0;
}
void dfs_color(int x, int fa, int c) {
  col[x] = c, ccnt[x][c]++;
  for (int i = 0; i < edg[x].size(); i++)
    if (edg[x][i] != fa) {
      int y = edg[x][i];
      dfs_color(y, x, c ^ 1);
      ccnt[x][0] += ccnt[y][0], ccnt[x][1] += ccnt[y][1];
    }
}
namespace TreeCase {
int dfs(int x, int fa) {
  int ret = 0;
  for (int i = 0; i < edg[x].size(); i++)
    if (edg[x][i] != fa) {
      int y = edg[x][i];
      ret += dfs(y, x) + abs(ccnt[y][0] - ccnt[y][1]);
    }
  return ret;
}
void work() {
  dfs_color(1, 0, 0);
  if (ccnt[1][0] != ccnt[1][1]) {
    cout << -1 << endl;
    return;
  }
  int ans = dfs(1, 0);
  cout << ans << endl;
}
}  // namespace TreeCase
namespace CircleCase {
namespace EvenCase {}
namespace OddCase {}
void work() {}
}  // namespace CircleCase
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    edg[x].push_back(y), edg[y].push_back(x);
  }
  if (m == n - 1)
    TreeCase::work();
  else
    CircleCase::work();
  return 0;
}
