#include <bits/stdc++.h>
using namespace std;
long double TL = 1.0;
bool is_tl = 0;
long long CALLS = 0;
inline bool IS() {
  if (++CALLS == 1000) {
    CALLS = 0;
    is_tl |= clock() > (TL - 0.1) * CLOCKS_PER_SEC;
  }
  return is_tl;
}
template <typename T1, typename T2>
inline void amin(T1 &a, T2 b) {
  if (a > b) a = b;
}
template <typename T1, typename T2>
inline void amax(T1 &a, T2 b) {
  if (a < b) a = b;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, pair<T1, T2> &p) {
  os << p.first << ' ' << p.second << endl;
  return os;
}
template <typename T1, typename T2>
istream &operator>>(istream &is, pair<T1, T2> &p) {
  is >> p.first >> p.second;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto &u : v) os << u << ' ';
  os << endl;
  return os;
}
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const long long N = 2e5 + 7, NS = 2e3 + 7, lg = 19, sq = 550, inf = 1e9 + 7,
                SM = 1e2 + 7;
const long double eps = 1e-9;
long long hash_mod[4] = {1000000007, 998244353, 1000000009, 999999937},
          mod = hash_mod[rnd() % 4];
long long hash_pows[4] = {179, 239, 1007, 2003}, P = hash_pows[rnd() % 4];
vector<long long> v[N];
long long id, s[N][2], ans = 0;
void dfs(long long x, long long p, long long d) {
  if (d % 2 == id) s[x][id]++;
  for (auto u : v[x]) {
    if (u == p) continue;
    dfs(u, x, d + 1);
    s[x][id] += s[u][id];
  }
  if (id == 1) ans += abs(s[x][0] - s[x][1]);
}
void solve() {
  long long n, m;
  cin >> n >> m;
  if (n == m) return;
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    a--, b--;
    v[a].push_back(b);
    v[b].push_back(a);
  }
  id = 0;
  dfs(0, -1, 0);
  id = 1;
  dfs(0, -1, 0);
  if (s[0][0] != s[0][1])
    cout << -1;
  else
    cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
}
