#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
vector<int> adjlist[100005];
int U[N], V[N];
int a[N];
int num[N];
int p[N], d[N];
int col[N];
int ans = 0;
void dfs2(int u) {
  for (auto v : adjlist[u]) {
    if (d[v] == d[u] + 1) {
      dfs2(v);
      num[u] += num[v];
    }
  }
  ans += abs(num[u]);
}
void dfs1(int u) {
  for (auto v : adjlist[u]) {
    if (col[v] == -1) {
      d[v] = d[u] + 1;
      col[v] = 1 ^ col[u];
      p[v] = u;
      dfs1(v);
    }
  }
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &U[i], &V[i]);
    adjlist[U[i]].push_back(V[i]);
    adjlist[V[i]].push_back(U[i]);
  }
  memset(col, -1, sizeof(col));
  col[1] = 0;
  p[1] = 1;
  dfs1(1);
  for (int i = 1; i <= n; i++) {
    num[i] = col[i] ? -1 : 1;
  }
  dfs2(1);
  if (n - 1 == m) {
    if (num[1]) {
      printf("-1");
    } else
      printf("%d", ans);
    return 0;
  }
  for (int i = 0; i < m; i++) {
    if (p[U[i]] != V[i] && p[V[i]] != U[i]) {
      if (d[U[i]] < d[V[i]]) swap(U[i], V[i]);
      if (col[U[i]] != col[V[i]]) {
        int cur = U[i];
        vector<int> li;
        while (cur != V[i]) {
          li.push_back(num[cur]);
          cur = p[cur];
        }
        li.push_back(num[cur]);
        sort(li.begin(), li.end());
        int x = li[li.size() / 2];
        for (int i = 1; i <= n; i++) {
          num[i] = col[i] ? -1 : 1;
        }
        cur = U[i];
        while (cur != V[i]) {
          num[cur] -= x;
          cur = p[cur];
        }
        num[cur] -= x;
        ans = 0;
        dfs2(1);
      } else {
        int x = num[V[i]] / 2;
        for (int i = 1; i <= n; i++) {
          num[i] = col[i] ? -1 : 1;
        }
        num[U[i]] -= x;
        num[V[i]] -= x;
        ans = abs(x);
        dfs2(1);
      }
      if (num[1]) {
        printf("-1");
      } else
        printf("%d", ans);
      return 0;
    }
  }
}
