#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using D = double;
using uint = unsigned int;
const int maxn = 100005;
vector<int> gr[maxn];
int n, m;
ll answer;
int go(int cur, int pr) {
  int curb = 0;
  for (auto v : gr[cur])
    if (v != pr) {
      auto t = go(v, cur);
      curb += t;
      answer += abs(t);
    }
  if (curb == 0) return 1;
  if (curb > 0) {
    return -(curb - 1);
  }
  return -curb + 1;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--, b--;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  auto t = go(0, -1);
  if (t == 0) {
    cout << answer << endl;
  } else
    cout << -1 << endl;
  return 0;
}
