#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool cmin(T& a, const T& b) {
  return a > b ? a = b, 1 : 0;
}
template <typename T>
inline bool cmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
template <typename T>
void read(T& x) {
  int f = 1;
  char ch;
  x = 0;
  while (!isdigit(ch = getchar()))
    if (ch == '-') f = -1;
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
}
const int NX = 200010;
int n, m;
vector<int> edge[NX];
namespace tree {
long long ans = 0;
int dfs(int x, int fa, int d) {
  int cur_size = (d & 1) ? 1 : -1;
  for (int y : edge[x]) {
    if (y != fa) {
      cur_size += dfs(y, x, d + 1);
    }
  }
  ans += abs(cur_size);
  return cur_size;
}
void solve() {
  if (dfs(1, 0, 1))
    puts("-1");
  else
    cout << ans << "\n";
}
}  // namespace tree
namespace graph {
void solve() {}
}  // namespace graph
int main() {
  read(n);
  read(m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    read(u);
    read(v);
    edge[u].push_back(v);
    edge[v].push_back(u);
  }
  if (m == n - 1)
    tree::solve();
  else
    graph::solve();
  return 0;
}
