#include <bits/stdc++.h>
using namespace std;
int n, m;
struct edge {
  int y, nxt;
  edge() {}
  edge(int yy, int nn) { y = yy, nxt = nn; }
} e[101 * 2];
int head[101], ecnt;
void addedge(int x, int y) {
  ecnt++;
  e[ecnt] = edge(y, head[x]);
  head[x] = ecnt;
  return;
}
int vis[101], w[101], w2[101];
int X, Y, P;
void dfs1(int u, int last) {
  vis[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].y;
    if (v != last) {
      if (vis[v]) {
        X = u, Y = v;
      } else {
        w[v] = -w[u];
        dfs1(v, u);
      }
    }
  }
  return;
}
void dfs2(int u, int last) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].y;
    if (v != last && ((u != X || v != Y) && (u != Y || v != X))) {
      dfs2(v, u);
      w[u] += w[v];
      w2[u] += w2[v];
    }
  }
  return;
}
int sta[101], top;
int main() {
  {
    n = 0;
    char ch;
    int f = 0;
    do {
      ch = getchar();
      if (ch == '-') {
        f = 1;
      }
    } while (ch < '0' || ch > '9');
    while ('0' <= ch && ch <= '9') {
      n = (n << 1) + (n << 3) + ch - 48;
      ch = getchar();
    }
    if (f) n = -n;
  }
  {
    m = 0;
    char ch;
    int f = 0;
    do {
      ch = getchar();
      if (ch == '-') {
        f = 1;
      }
    } while (ch < '0' || ch > '9');
    while ('0' <= ch && ch <= '9') {
      m = (m << 1) + (m << 3) + ch - 48;
      ch = getchar();
    }
    if (f) m = -m;
  }
  int x, y;
  for (int i = 1; i <= m; i++) {
    {
      x = 0;
      char ch;
      int f = 0;
      do {
        ch = getchar();
        if (ch == '-') {
          f = 1;
        }
      } while (ch < '0' || ch > '9');
      while ('0' <= ch && ch <= '9') {
        x = (x << 1) + (x << 3) + ch - 48;
        ch = getchar();
      }
      if (f) x = -x;
    }
    {
      y = 0;
      char ch;
      int f = 0;
      do {
        ch = getchar();
        if (ch == '-') {
          f = 1;
        }
      } while (ch < '0' || ch > '9');
      while ('0' <= ch && ch <= '9') {
        y = (y << 1) + (y << 3) + ch - 48;
        ch = getchar();
      }
      if (f) y = -y;
    }
    addedge(x, y);
    addedge(y, x);
  }
  w[1] = 1;
  dfs1(1, 0);
  if (n == m && w[X] == w[Y]) {
    P = 1;
  }
  int cnt = 0, ans = 0;
  for (int i = 1; i <= n; i++) {
    cnt += w[i];
  }
  if (n != m && cnt) {
    puts("-1");
    return 0;
  } else if (n == m) {
    if (P == 1) {
      if (cnt & 1) {
        puts("-1");
        return 0;
      }
      ans = abs(cnt) / 2;
      w[X] -= cnt / 2;
      w[Y] -= cnt / 2;
    } else {
      if (cnt) {
        puts("-1");
        return 0;
      }
      w2[X] = 1, w2[Y] = -1;
    }
  }
  dfs2(1, 0);
  for (int i = 1; i <= n; i++) {
    if (!w2[i]) {
      ans += abs(w[i]);
    } else {
      if (w2[i]) {
        w[i] = -w[i];
      }
      sta[++top] = w[i];
    }
  }
  sta[++top] = 0;
  sort(sta + 1, sta + top + 1);
  int tmp = sta[(top + 1) / 2];
  for (int i = 1; i <= top; i++) {
    ans += abs(sta[i] - tmp);
  }
  printf("%d\n", ans);
  return 0;
}
