#include <bits/stdc++.h>
using namespace std;
const long long MOD = static_cast<int>(1e9) + 7;
using namespace std::rel_ops;
inline long long bit(int x) { return 1LL << x; }
template <class T>
inline int size(const T& a) {
  return (int)a.size();
}
template <class T>
inline bool chmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <class T>
inline int clamp(T v, T lo, T hi) {
  return (v > hi) - (v < lo);
}
template <class T>
inline bool chmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <class T>
inline pair<vector<T>, char> operator*(const vector<T>& v, const char& c) {
  return make_pair(v, c);
}
template <class T>
inline istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) is >> x;
  return is;
}
template <class T>
inline ostream& operator<<(ostream& os, const pair<vector<T>, char>& v) {
  bool t = 0;
  for (const T& x : v.first) {
    if (t) os << v.second;
    os << x;
    t = 1;
  }
  return os;
}
template <class T>
inline ostream& operator<<(ostream& os, vector<T>& v) {
  return os << v * ' ';
}
struct before_main {
  before_main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);
    ;
  };
} __before_main;
int a[101010], b[101010];
int color[101010];
vector<int> E[101010];
int deg[101010];
int ans;
int dfs(int v, int par) {
  if (E[v].size() == 1) {
    return 1;
  }
  int odd = 0, even = 0;
  for (const int& w : E[v]) {
    if (w == par) continue;
    int res = dfs(w, v);
    if (res == 1) odd++;
    if (res == 2) even++;
  }
  if (v != 0) {
    if (odd % 2 == 0) {
      ans += even;
      ans += odd;
      return 1;
    } else {
      ans += even;
      ans += odd;
      return 2;
    }
  } else {
    if (odd % 2 == 1) {
      ans += odd;
      ans += even;
      cout << ans << endl;
      exit(0);
    } else {
      cout << -1 << endl;
      exit(0);
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  if (m != n - 1) {
    exit(1);
  }
  for (int i = 0, i_len = static_cast<int>(m); i < i_len; i++) {
    cin >> a[i] >> b[i];
    a[i]--;
    b[i]--;
    E[b[i]].push_back(a[i]);
    E[a[i]].push_back(b[i]);
  }
  dfs(0, 0);
}
