#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
int n, m;
vector<int> g[N];
long long dp[N], res;
void dfs(int u, int par) {
  for (int i = (0); i <= (int(int((g[u]).size())) - 1); ++i) {
    int v = g[u][i];
    if (v == par) continue;
    dfs(v, u);
    dp[u] -= dp[v];
  }
  dp[u]++;
  res += abs(dp[u]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = (0); i <= (int(m) - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(0, -1);
  if (dp[0] == 0)
    printf("%lld\n", res);
  else
    printf("-1\n");
  return 0;
}
