#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], DEPTH[maxn];
int cyclePar;
bool visited[maxn], cycleEdge[maxn];
vector<pair<int, int> > graph[maxn];
pair<int, int> CYCLEEDGE;
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 = make_pair(u, i.first);
      cycleEdge[i.second] = true;
      cyclePar = (1 + DEPTH[i.first] - DEPTH[u]) & 1;
    }
  }
}
void calcToken(int u, int depth = 0) {
  DEPTH[u] = depth;
  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] && !cycleEdge[i.second]) {
      calcToken(i.first, depth + 1);
      sz[u] += sz[i.first];
      cntToken[u] += cntToken[i.first];
    }
  }
}
void getCntToken(int u) {
  visited[u] = true;
  cntToken[u] = token[u];
  for (auto i : graph[u]) {
    if (!visited[i.first] && !cycleEdge[i.second]) {
      getCntToken(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] && !cycleEdge[i.second]) {
      res += abs(cntToken[i.first]);
      res += solve(i.first);
    }
  }
  return res;
}
int SOLVE(int K) {
  token[CYCLEEDGE.first] -= K;
  token[CYCLEEDGE.second] += K;
  memset(visited, false, sizeof(visited));
  getCntToken(0);
  memset(visited, false, sizeof(visited));
  int res = solve(0);
  token[CYCLEEDGE.first] += K;
  token[CYCLEEDGE.second] -= K;
  return res + abs(K);
}
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 {
    memset(visited, false, sizeof(visited));
    getCycle(0);
    memset(visited, false, sizeof(visited));
    calcToken(0);
    memset(visited, false, sizeof(visited));
    if (cyclePar & 1) {
      if ((cnt & 1) != ((n - cnt) & 1)) {
        cout << -1 << endl;
      } else {
        int K = ((n - cnt) - cnt) / 2;
        for (int i = 0; i < n; i++)
          for (auto j : graph[i]) {
            if (cycleEdge[j.second]) {
              token[j.first] += K;
            }
          }
        memset(visited, false, sizeof(visited));
        getCntToken(0);
        memset(visited, false, sizeof(visited));
        cout << solve(0) + abs(K) << endl;
      }
    } else {
      if ((n & 1) || cnt != n / 2) {
        cout << -1 << endl;
      } else {
        int l = -maxn, r = maxn, mid1, mid2;
        while (r - l > 4) {
          mid1 = (2 * l + r) / 3;
          mid2 = (l + 2 * r) / 3;
          int val1 = SOLVE(mid1), val2 = SOLVE(mid2);
          if (val1 == val2)
            l = mid1, r = mid2;
          else if (val1 < val2)
            r = mid2;
          else
            l = mid1;
        }
        int ans = mod;
        for (int i = l; i <= r; i++) ans = min(ans, SOLVE(i));
        cout << ans << endl;
      }
    }
  }
}
