#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int n, m;
int deep[N];
int token[N];
int capa[N];
pair<int, int> edge[N];
bool in_cycle[N];
vector<int> G[N];
void dfs(int v = 0, int par = 0) {
  deep[v] = 1 + deep[par];
  for (int u : G[v])
    if (u != par) dfs(u, v);
}
void calc(int v = 0, int par = 0) {
  for (int u : G[v])
    if (u != par) {
      calc(u, v);
      token[v] += token[u];
      capa[v] += capa[u];
    }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    cin >> edge[i].first >> edge[i].second;
    edge[i].first--, edge[i].second--;
    G[edge[i].first].push_back(edge[i].second);
    G[edge[i].second].push_back(edge[i].first);
  }
  if (m == n - 1) {
    dfs();
    int mod[2];
    for (int i = 0; i < n; i++) mod[deep[i] & 1]++;
    if (mod[0] != mod[1]) return cout << "-1\n", 0;
    for (int i = 0; i < n; i++)
      if (deep[i] & 1)
        token[i]++;
      else
        capa[i]++;
    calc();
    int ans = 0;
    for (int i = 0; i < m; i++) {
      if (deep[edge[i].second] < deep[edge[i].first])
        swap(edge[i].first, edge[i].second);
      ans += abs(token[edge[i].second] - capa[edge[i].second]);
    }
    return cout << ans << "\n", 0;
  }
  exit(-1);
  return 0;
}
