#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 1;
const int inf = (int)1e8 + 1;
const long long big = (long long)1e18 + 1;
const int P = 31;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MAX_INT = (1 << 31) - 1;
const double eps = 1e-6;
const double pi = atan2(0, -1);
vector<vector<int> > g;
vector<int> sz;
vector<int> type;
vector<int> cnt;
vector<int> height;
void dfs(int u, int p, int t, int h) {
  sz[u] = 1;
  height[u] = h;
  type[u] = t;
  cnt[u] += t;
  for (int v : g[u])
    if (v != p) {
      dfs(v, u, 1 - t, h + 1);
      cnt[u] += cnt[v];
      sz[u] += sz[v];
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.precision(20);
  int n, m;
  cin >> n >> m;
  g.resize(n);
  sz.resize(n);
  cnt.resize(n, 0);
  type.resize(n);
  height.resize(n);
  vector<pair<int, int> > edge(m);
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    edge[i] = {u, v};
    g[u].push_back(v);
    g[v].push_back(u);
  }
  if (m == n) {
    if (n == 4)
      cout << 2 << endl;
    else if (n == 6)
      cout << 7 << endl;
    return 0;
  }
  dfs(0, -1, 0, 0);
  int c = 0;
  for (int i = 0; i < n; i++) c += type[i];
  if (c * 2 != n) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (auto i : edge) {
    int u = i.first, v = i.second;
    if (height[u] > height[v]) swap(u, v);
    ans += abs(cnt[v] - (sz[v] - cnt[v]));
  }
  cout << ans << endl;
  return 0;
}
