#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> v[65536 * 2];
int dep[65536 * 2];
int siz[65536 * 2];
int ans = 0;
int cnt[2];
void dfs(int x, int p) {
  dep[x] = dep[p] ^ 1;
  cnt[dep[x]]++;
  if (dep[x] == 0)
    siz[x] = -1;
  else
    siz[x] = 1;
  for (int i = 0; i < v[x].size(); i++) {
    if (v[x][i] == p) continue;
    dfs(v[x][i], x);
    siz[x] += siz[v[x][i]];
  }
  ans += abs(siz[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  if (m == n - 1) {
    dfs(1, 0);
    if (cnt[0] != cnt[1])
      puts("-1");
    else
      printf("%lld\n", ans);
    return 0;
  }
  return 0;
}
