#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const long long LINF = 2e16;
const int INF = 1e9;
const int magic = 348;
const double eps = 1e-10;
const double pi = 3.14159265;
inline int getint() {
  char ch;
  int res;
  bool f;
  while (!isdigit(ch = getchar()) && ch != '-') {
  }
  if (ch == '-')
    f = false, res = 0;
  else
    f = true, res = ch - '0';
  while (isdigit(ch = getchar())) res = res * 10 + ch - '0';
  return f ? res : -res;
}
int n, e;
vector<int> v[100048];
namespace tree {
int depth[100048];
int cnt[100048][2];
inline int myabs(int first) { return first >= 0 ? first : -first; }
inline void dfs(int cur, int father) {
  int i, second;
  cnt[cur][0] = cnt[cur][1] = 0;
  cnt[cur][depth[cur]] = 1;
  for (i = 0; i < int(v[cur].size()); i++) {
    second = v[cur][i];
    if (second != father) {
      depth[second] = depth[cur] ^ 1;
      dfs(second, cur);
      cnt[cur][0] += cnt[second][0];
      cnt[cur][1] += cnt[second][1];
    }
  }
}
inline int solve() {
  int i, first, second;
  for (i = 1; i <= e; i++)
    first = getint(), second = getint(), v[first].push_back(second),
    v[second].push_back(first);
  depth[1] = 1;
  dfs(1, -1);
  if (cnt[1][0] != cnt[1][1]) return -1;
  int res = 0;
  for (i = 2; i <= n; i++) res += myabs(cnt[i][0] - cnt[i][1]);
  return res;
}
}  // namespace tree
int main() {
  n = getint();
  e = getint();
  if (e == n - 1) {
    printf("%d\n", tree::solve());
    return 0;
  }
  return 0;
}
