#include <bits/stdc++.h>
using namespace std;
namespace std {
template <typename T, typename U>
struct hash<pair<T, U>> {
  hash<T> t;
  hash<U> u;
  size_t operator()(const pair<T, U>& p) const {
    return t(p.first) ^ (u(p.second) << 7);
  }
};
}  // namespace std
template <typename T, typename F>
T bsh(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      l = m + 1;
      r = m;
    } else {
      h = m - 1;
    }
  }
  return r;
}
template <typename T, typename F>
T bsl(T l, T h, const F& f) {
  T r = -1, m;
  while (l <= h) {
    m = (l + h) / 2;
    if (f(m)) {
      h = m - 1;
      r = m;
    } else {
      l = m + 1;
    }
  }
  return r;
}
template <typename T>
T gcd(T a, T b) {
  if (a < b) swap(a, b);
  return b ? gcd(b, a % b) : a;
}
template <typename T>
void fracn(pair<T, T>& a) {
  auto g = gcd(a.first, a.second);
  a.first /= g;
  a.second /= g;
}
template <typename T>
struct Index {
  int operator[](const T& t) {
    auto i = m.find(t);
    return i != m.end() ? i->second : m[t] = m.size();
  }
  int s() { return m.size(); }
  unordered_map<T, int> m;
};
int N, M;
struct X {
  vector<int> E;
  vector<int> C;
  int c;
  int b, w;
  int p;
};
vector<X> V;
void dfs(int u, int ig) {
  V[u].p = ig;
  for (int v : V[u].E)
    if (v != ig) {
      V[u].C.push_back(v);
      dfs(v, u);
    }
  V[u].c = V[u].C.size();
  V[u].b = 0;
  V[u].w = 0;
}
int main(int, char**) {
  ios_base::sync_with_stdio(false);
  cin >> N >> M;
  if (N == M) return 0;
  if (N % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }
  V.resize(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    V[a].E.push_back(b);
    V[b].E.push_back(a);
  }
  dfs(0, -1);
  queue<int> L;
  for (int i = 0; i < N; i++) {
    if (V[i].c == 0) L.push(i);
  }
  int ans = 0;
  while (!L.empty()) {
    int u = L.front();
    L.pop();
    int bal = V[u].b - V[u].w - 1;
    if (V[u].p != -1) {
      int v = V[u].p;
      if (bal > 0) {
        V[v].w += bal;
      } else if (bal < 0) {
        V[v].b -= bal;
      }
      ans += abs(bal);
      V[v].c -= 1;
      if (V[v].c == 0) {
        L.push(v);
      }
    } else {
      if (bal != 0) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  cout << ans << endl;
}
