#include <bits/stdc++.h>
using namespace std;
vector<int> G[(100000 + 5)];
bool col[(100000 + 5)];
int ans;
void Dfs(int now, int F) {
  for (int i = (0); i <= (int)(G[now].size() - 1); ++i)
    if (G[now][i] != F) Dfs(G[now][i], now);
  if (!col[now]) col[now] ^= 1, col[F] ^= 1, ++ans;
}
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 (n == 1) {
    puts("-1");
    return 0;
  }
  Dfs(1, 0);
  if (col[0])
    puts("-1");
  else
    printf("%d\n", ans);
  return 0;
}
