#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <int n, class... T>
typename enable_if<(n >= sizeof...(T))>::type _ot(ostream &,
                                                  tuple<T...> const &) {}
template <int n, class... T>
typename enable_if<(n < sizeof...(T))>::type _ot(ostream &os,
                                                 tuple<T...> const &t) {
  os << (n == 0 ? "" : ", ") << get<n>(t);
  _ot<n + 1>(os, t);
}
template <class... T>
ostream &operator<<(ostream &o, tuple<T...> const &t) {
  o << "(";
  _ot<0>(o, t);
  o << ")";
  return o;
}
template <class T, class U>
ostream &operator<<(ostream &o, pair<T, U> const &p) {
  o << "(" << p.first << ", " << p.second << ")";
  return o;
}
template <class T>
ostream &operator<<(ostream &o, const stack<T> &a) {
  o << "{";
  for (auto tmp = a; tmp.size(); tmp.pop())
    o << (a.size() == tmp.size() ? "" : ", ") << tmp.top();
  o << "}";
  return o;
}
template <class T,
          class = typename iterator_traits<typename T::iterator>::value_type,
          class = typename enable_if<!is_same<T, string>::value>::type>
ostream &operator<<(ostream &o, const T &a) {
  for (auto ite = a.begin(); ite != a.end(); ++ite)
    o << (ite == a.begin() ? "" : " ") << *ite;
  return o;
}
const int N = 1e5;
int n, m;
vector<vector<int>> g(N);
int cycleSize() {
  vector<int> used(n);
  vector<int> dist(n);
  const function<int(int, int)> dfs = [&](int i, int p) {
    if (used[i]) {
      return dist[p] + 1;
    }
    used[i] = 1;
    for (int j : g[i])
      if (j != p) {
        dist[j] = dist[i] + 1;
        int d = dfs(j, i);
        if (d != -1) return d;
      }
    return -1;
  };
  dist[0] = 0;
  return dfs(0, -1);
}
int color[N];
int used[N];
void initColor(int i, int c = 0) {
  used[i] = 1;
  color[i] = c;
  for (int j : g[i])
    if (!used[j]) {
      initColor(j, !c);
    }
}
int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  cin >> n >> m;
  if (n == 2) {
    cout << 1 << endl;
    return 0;
  }
  if (n % 2 == 1) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> deg(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
    deg[a]++;
    deg[b]++;
  }
  ll ans = 0;
  if (n == m) {
    int c = cycleSize();
    if (c % 2 == 1) {
      cout << -1 << endl;
      return 0;
    }
    ans += c / 2;
    assert(0);
  }
  initColor(0);
  vector<vector<int>> w(2, vector<int>(n));
  vector<int> used(n);
  queue<int> q;
  int sum[2] = {};
  for (int i = 0; i < n; i++) {
    w[color[i]][i]++;
    sum[color[i]]++;
    if (g[i].size() == 1) {
      q.emplace(i);
    }
  }
  if (sum[0] != sum[1]) {
    cout << -1 << endl;
    return 0;
  }
  while (q.size()) {
    int i = q.front();
    q.pop();
    if (deg[i] == 0) {
      break;
    }
    used[i] = 1;
    int m = min(w[0][i], w[1][i]);
    w[0][i] -= m;
    w[1][i] -= m;
    ans += w[0][i] | w[1][i];
    for (int j : g[i])
      if (!used[j]) {
        deg[j]--;
        for (int c = 0; c < 2; c++) w[c][j] += w[c][i];
        if (deg[j] == 1) {
          q.emplace(j);
        }
        break;
      }
  }
  cout << ans << endl;
  return 0;
}
