#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100030;
const long long MODD = 1000000009;
vector<int> adj[MAX_N];
int A[MAX_N];
long long ans = 0;
int f(int v, int p) {
  int val = -1;
  for (int u : adj[v])
    if (u != p) {
      int x = f(u, v);
      ans += abs(x);
      val -= x;
    }
  return val;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  if (m != n - 1) {
    cout << 0 << endl;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  if (f(0, -1) == 0) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
