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