#include <bits/stdc++.h>
using namespace std;
struct node {
  int to, next;
} e[1000005 << 1];
int head[1000005], n, m, cnt, f[1000005];
long long ans;
void add(int x, int y) {
  e[cnt] = (node){y, head[x]};
  head[x] = cnt++;
}
void dfs(int x, int from) {
  for (int i = head[x]; i != -1; i = e[i].next) {
    int to1 = e[i].to;
    if (to1 != from) {
      dfs(to1, x);
      f[x] -= f[to1];
    }
  }
  f[x]--;
  ans += abs(f[x]);
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == m) return 0;
  memset(head, -1, sizeof(head));
  for (int i = 1, x, y; i <= m; i++)
    scanf("%d%d", &x, &y), add(x, y), add(y, x);
  dfs(1, 0);
  if (f[1] != 0) return puts("-1"), 0;
  printf("%lld\n", ans);
}
