#include <bits/stdc++.h>
using namespace std;
template <class C>
void mini(C& _a4, C _b4) {
  _a4 = min(_a4, _b4);
}
template <class C>
void maxi(C& _a4, C _b4) {
  _a4 = max(_a4, _b4);
}
template <class TH>
void _dbg(const char* sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char* sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream& operator<<(ostream& os, vector<T> V) {
  os << "[";
  for (auto& vv : V) os << vv << ",";
  os << "]";
  return os;
}
long long out;
vector<long long> d[100100];
long long dfs(long long v, long long oj) {
  long long bil = 0;
  for (long long el : d[v]) {
    if (oj == el) continue;
    bil += dfs(el, v);
  }
  long long res = 1 - bil;
  out += abs(res);
  return res;
}
long long n, m;
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n >> m;
  for (long long i = (0); i <= ((long long)(m)-1); i++) {
    long long a, b;
    cin >> a >> b;
    a--;
    b--;
    d[a].push_back(b);
    d[b].push_back(a);
  }
  if (dfs(0, -1) != 0) {
    cout << "-1\n";
  } else
    cout << out << endl;
}
