#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
long long n, m, sol, cnt;
int siz[MAXN], br[MAXN], bio[MAXN], par[MAXN], nul[MAXN];
int mg[MAXN], aa, bb;
vector<int> v[MAXN];
bool oboji(int x, int rod, int col) {
  siz[x] = 1;
  br[x] += col;
  nul[x] = (br[x] == 0);
  for (auto sus : v[x]) {
    if (sus == rod || x == aa && sus == bb || x == bb && sus == aa) continue;
    oboji(sus, x, !col);
    siz[x] += siz[sus];
    br[x] += br[sus];
    nul[x] += nul[sus];
  }
  sol += abs(nul[x] - br[x]);
}
void ciklus(int x, int y) {
  aa = x;
  bb = y;
  cnt = 1;
  while (x != y) {
    mg[x] = 1;
    x = par[x];
    cnt++;
  }
}
void dfs(int x, int rod) {
  par[x] = rod;
  bio[x] = 1;
  for (auto sus : v[x]) {
    if (sus == rod) continue;
    if (bio[sus] == 0) {
      dfs(sus, x);
    } else if (bio[sus] == 1) {
      ciklus(x, sus);
    }
  }
  bio[x] = 2;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  if (n % 2 == 1) {
    cout << -1;
    return 0;
  }
  if (m == n - 1) {
    oboji(1, 0, 0);
    if (br[1] * 2 == n)
      cout << sol;
    else
      cout << -1;
  } else {
    dfs(1, 0);
    oboji(1, 0, 0);
    if (cnt % 2 == 0) {
      sol = 0;
      vector<int> v;
      v.push_back(0);
      for (int i = 2; i <= n; i++) {
        if (mg[i] == 0) {
          sol += abs(siz[i] - 2 * br[i]);
        } else {
          v.push_back(siz[i] - 2 * br[i]);
        }
      }
      sort(v.begin(), v.end());
      int md = v[v.size() / 2];
      for (auto x : v) {
        sol += abs(md - x);
      }
    } else {
      sol = 0;
      int k = n - br[1] * 2, tot = br[1];
      memset(br, 0, sizeof br);
      br[aa] += abs(k / 2);
      br[bb] += abs(k / 2);
      if (tot * 2 <= n)
        oboji(1, 0, 0);
      else
        oboji(1, 0, 1);
      sol += abs(k / 2);
    }
    cout << sol;
  }
  return 0;
}
