#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> E[101010];
int num[101010][2];
signed long long sum;
void dfs(int cur, int pre, int odd) {
  num[cur][odd]++;
  for (auto& r : E[cur])
    if (r != pre) {
      dfs(r, cur, odd ^ 1);
      num[cur][0] += num[r][0];
      num[cur][1] += num[r][1];
    }
  sum += abs(num[cur][0] - num[cur][1]);
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  cin >> N >> M;
  for (i = 0; i < (M); i++) {
    cin >> x >> y;
    E[x - 1].push_back(y - 1);
    E[y - 1].push_back(x - 1);
  }
  if (M == N) return;
  dfs(0, -1, 0);
  if (num[0][0] != num[0][1]) cout << -1 << endl;
  cout << sum << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false), cin.tie(0);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
