#include <bits/stdc++.h>
using namespace std;
int n, m, x, y, i;
vector<int> list[100011];
int col[100011];
int dp[100011];
long long ans;
void dfs(int node, int dad) {
  for (auto to : list[node]) {
    if (to == dad) continue;
    col[to] = col[node] ^ 1;
    dfs(to, node);
  }
}
long long abss(long long a) {
  if (a < 0) return -a;
  return a;
}
void solve(int node, int root) {
  dp[node] = (col[node] ? 1 : -1);
  for (auto to : list[node]) {
    if (to == root) continue;
    solve(to, node);
    dp[node] += dp[to];
  }
  ans += 1LL * abss(dp[node]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    list[x].push_back(y);
    list[y].push_back(x);
  }
  if (n - 1 != m) return 0;
  dfs(1, 0);
  solve(1, 0);
  if (dp[1] != 0) {
    printf("-1");
    return 0;
  }
  printf("%lld", ans);
  return 0;
}
