#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<int> E[101010];
signed long long sum;
int dfs(int cur, int pre, int type) {
  int ret = type;
  for (auto& r : E[cur])
    if (r != pre) ret += dfs(r, cur, -type);
  sum += abs(ret);
  return ret;
}
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 - 1) {
    x = dfs(0, -1, 1);
    if (x != 0) sum = -1;
    cout << sum << endl;
  }
  if (M == N) assert(0);
}
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;
}
