#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
const long long inf = 2e18, mod = 1e9 + 7;
int n, m, token[maxn], cntToken[maxn], sz[maxn];
bool visited[maxn], cycleEdge[maxn];
vector<pair<int, int> > graph[maxn];
void getCycle(int u, int prev = -1) {
  visited[u] = true;
  for (pair<int, int> i : graph[u]) {
    if (!visited[i.first]) {
      getCycle(i.first, u);
    } else if (i.first != prev) {
      cycleEdge[i.second] = true;
    }
  }
}
void calcToken(int u, int depth = 0) {
  visited[u] = true;
  sz[u] = 1;
  token[u] = (depth & 1 ? 1 : -1);
  cntToken[u] = token[u];
  for (auto i : graph[u]) {
    if (!visited[i.first]) {
      calcToken(i.first, depth + 1);
      sz[u] += sz[i.first];
      cntToken[u] += cntToken[i.first];
    }
  }
}
int solve(int u) {
  visited[u] = true;
  int res = 0;
  for (auto i : graph[u]) {
    if (!visited[i.first]) {
      res += abs(cntToken[i.first]);
      res += solve(i.first);
    }
  }
  return res;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  int u, v;
  for (int i = 0; i < m; i++) {
    cin >> u >> v;
    graph[--u].push_back(make_pair(--v, i));
    graph[v].push_back(make_pair(u, i));
  }
  calcToken(0);
  int cnt = 0;
  for (int i = 0; i < n; i++) cnt += (token[i] == 1);
  if (m == n - 1) {
    if ((n & 1) || cnt != n / 2) {
      cout << -1 << endl;
    } else {
      memset(visited, false, sizeof(visited));
      cout << solve(0) << endl;
    }
  } else {
    getCycle(0);
  }
}
