#include <bits/stdc++.h>
using namespace std;
struct edge {
  int t, next;
} e[100005 * 2];
int ecnt, head[100005];
void addedge(int f, int t) {
  e[++ecnt] = (edge){t, head[f]};
  head[f] = ecnt;
  e[++ecnt] = (edge){f, head[t]};
  head[t] = ecnt;
}
long long ans;
int DFS(int u, int fr) {
  int delta = 1;
  for (int i = head[u]; i; i = e[i].next) {
    if (e[i].t != fr) {
      int t = DFS(e[i].t, u);
      delta -= t;
    }
  }
  ans += abs(delta);
  return delta;
}
int n, m;
void solve1() {
  int t = DFS(1, 0);
  if (t != 0) {
    puts("-1");
    exit(0);
  }
}
void solve2() {}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1, u, v; i <= m; i++) scanf("%d%d", &u, &v), addedge(u, v);
  if (m == n - 1)
    solve1();
  else
    solve2();
  cout << ans << endl;
  return 0;
}
