#include <bits/stdc++.h>
using namespace std;
int read() {
  int res = 0;
  char c = getchar();
  while (!isdigit(c)) c = getchar();
  while (isdigit(c)) res = res * 10 + c - '0', c = getchar();
  return res;
}
const int maxn = 1e5 + 5;
int N, M, dp[maxn], Ans;
vector<int> G[maxn];
void link(int u, int v) {
  G[u].push_back(v);
  G[v].push_back(u);
}
void dfs(int x, int fa, int col) {
  dp[x] = col;
  for (auto to : G[x])
    if (to != fa) dfs(to, x, col * -1), dp[x] += dp[to];
}
int main() {
  N = read(), M = read();
  for (register int i = 1; i <= M; i++) link(read(), read());
  dfs(1, 0, 1);
  for (register int i = 1; i <= N; i++) Ans += abs(dp[i]);
  printf("%d\n", !dp[1] ? Ans : -1);
  return 0;
}
