#include <bits/stdc++.h>
using namespace std;
constexpr long long TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
  os << "(" << p.first << "," << p.second << ")";
  return os;
}
template <class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  os << "{";
  for (int i = 0; i < (v.size()); i++) {
    if (i) os << ",";
    os << v[i];
  }
  os << "}";
  return os;
}
const int maxn = 100010;
pair<int, int> dfs(int v, int p, int d, long long& ans,
                   const vector<vector<int> >& g) {
  int a = (d & 1), b = !(d & 1);
  for (int to : g[v])
    if (to != p) {
      pair<int, int> res = dfs(to, v, d + 1, ans, g);
      ans += abs(res.first - res.second);
      a += res.first;
      b += res.second;
    }
  return make_pair(a, b);
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int> > g(N);
  for (int i = 0; i < (M); i++) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (M == N - 1) {
    long long ans = 0;
    pair<int, int> res = dfs(0, -1, 0, ans, g);
    if (res.first != res.second) ans = -1;
    cout << ans << endl;
  } else {
  }
  return 0;
}
