#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 1e5 + 5;
int n, m, ans;
int edge[MAX_N];
vector<int> G[MAX_N];
int dp[MAX_N];
void dfs(int v, int p = 0, int h = 0) {
  dp[v] = (h & 1 ? 1 : -1);
  for (int id : G[v]) {
    int u = edge[id] ^ v;
    if (u != p) {
      dfs(u, v, h + 1);
      dp[v] += dp[u];
    }
  }
  ans += abs(dp[v]);
}
void solve1() {
  dfs(0);
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int v, u;
    cin >> v >> u;
    v--, u--;
    edge[i] = v ^ u;
    G[v].push_back(i);
    G[u].push_back(i);
  }
  if (n & 1) {
    cout << "-1\n";
    return 0;
  }
  if (m == n - 1) {
    solve1();
    return 0;
  }
  exit(-1);
  return 0;
}
