#include <bits/stdc++.h>
using namespace std;
vector<int> G[(100000 + 5)];
int ans, c01[(100000 + 5)], c10[(100000 + 5)];
void Dfs(int now, int F) {
  int s01 = 0, s10 = 0;
  for (int i = (0); i <= (int)(G[now].size() - 1); ++i)
    if (G[now][i] != F) {
      Dfs(G[now][i], now);
      s01 += c01[G[now][i]];
      s10 += c10[G[now][i]];
    }
  if (s01 == s10 - 1) {
    ans += s01 + s10 - 1;
    return;
  }
  int a;
  if (s01 > s10) {
    a = s01;
    ans += a + (a - 1);
    c10[now] += (a - 1) - s10;
  } else {
    a = s10 + 1;
    ans += a + (a - 1);
    c01[now] += a - s01;
  }
}
int main() {
  int n, m, u, v;
  scanf("%d%d", &n, &m);
  for (int i = (1); i <= (int)(m); ++i) {
    scanf("%d%d", &u, &v);
    G[u].push_back(v);
    G[v].push_back(u);
  }
  if (m != n - 1) return 0;
  if (n == 1) {
    puts("-1");
    return 0;
  }
  Dfs(1, 0);
  if (c01[1] || c10[1])
    puts("-1");
  else
    printf("%d\n", ans >> 1);
  return 0;
}
