#include <bits/stdc++.h>
using namespace std;
vector<int> edges[110000];
int ans = 0;
int dp[110000];
int ok = 1;
void dfs2(int p, int a) {
  if (!ok) return;
  for (int i = 0; i < edges[a].size(); i++) {
    if (edges[a][i] != p) {
      dfs2(a, edges[a][i]);
    }
  }
  for (int i = 0; i < edges[a].size(); i++) {
    if (edges[a][i] != p) {
      int k = min(dp[a], dp[edges[a][i]]);
      dp[a] -= k;
      dp[edges[a][i]] -= k;
      ans += k;
      if (dp[edges[a][i]] > 0) {
        if (p < 0) {
          ok = 0;
          return;
        }
        dp[p] += dp[edges[a][i]];
        ans += 2 * dp[edges[a][i]];
        dp[edges[a][i]] = 0;
      }
    }
  }
}
int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  for (int i = 0; i < n; i++) dp[i] = 1;
  dfs2(-1, 0);
  if (!ok || dp[0] > 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
}
