#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
struct V {
  int head;
} v[N];
struct E {
  int u, v, next;
} e[N * 2];
int n, m, ecnt = 1, cnt, degree[N], cycle;
inline void add(int x, int y) {
  e[++ecnt].u = x, e[ecnt].v = y;
  e[ecnt].next = v[x].head, v[x].head = ecnt;
  e[++ecnt].u = y, e[ecnt].v = x;
  e[ecnt].next = v[y].head, v[y].head = ecnt;
  degree[x]++, degree[y]++;
}
int root;
void dfs(int x, int f, int &flag) {
  if (degree[x] == 1 && x != root) {
    flag = 1, cnt++;
    return;
  }
  for (int i = v[x].head; i; i = e[i].next) {
    int y = e[i].v;
    if (y == f) continue;
    int temp = 0;
    dfs(y, x, temp);
    flag ^= temp;
  }
  flag ^= 1;
  if (flag) cnt++;
}
int main() {
  scanf("%d %d\n", &n, &m);
  int tu, tv;
  for (int i = (1); i <= (m); ++i) scanf("%d %d\n", &tu, &tv), add(tu, tv);
  if (n == m) {
    for (int i = (1); i <= (n); ++i)
      if (degree[i] == 1) {
        break;
      }
    if (!cycle) cycle = 1;
  } else {
    int flag = 0;
    for (int i = (1); i <= (n); ++i)
      if (degree[i] == 1) {
        root = i, dfs(i, 0, flag);
        if (flag)
          printf("-1\n");
        else
          printf("%d\n", cnt);
        return 0;
      }
  }
  return 0;
}
