#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 1000;
vector<int> G[maxn];
int n, m;
int dp[maxn][2];
bool IsCircle[maxn];
int res;
void count(int u, int fa) {
  dp[u][0] = 1;
  dp[u][1] = 0;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v != fa && !IsCircle[v]) {
      count(v, u);
      dp[u][0] += dp[v][1];
      dp[u][1] += dp[v][0];
    }
  }
  res += abs(dp[u][0] - dp[u][1]);
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d %d", &a, &b);
    G[a].push_back(b);
    G[b].push_back(a);
  }
  if (m == n - 1) {
    res = 0;
    count(1, -1);
    if (dp[1][0] != dp[1][1])
      puts("-1");
    else
      printf("%d\n", res);
  }
  return 0;
}
