#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int n, m;
vector<int> adj[N];
int bal[N];
long long int res = 0;
void dfs(int u, int p) {
  bal[u] = 1;
  for (int v : adj[u])
    if (v != p) {
      dfs(v, u);
      bal[u] -= bal[v];
    }
  res += abs(bal[u]);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  if (m == n) return 0;
  for (int _ = 0; _ < (int)(m); _++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(0, -1);
  if (bal[0] != 0)
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}
