#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 9;
vector<int> V[N];
int n, m, cnt, g[N];
bool col[N];
void Dfs(int u, int fa) {
  for (auto v : V[u])
    if (v != fa) {
      Dfs(v, u);
      if (!col[v]) {
        if (col[u])
          ++g[u];
        else
          col[u] ^= 1;
        ++cnt;
      }
      g[u] -= g[v];
    }
  cnt += abs(g[u]);
}
int main() {
  scanf("%d%d", &n, &m);
  if (n == m) return 0;
  for (int i = 1, a, b; i <= m; ++i) {
    scanf("%d%d", &a, &b);
    V[a].emplace_back(b);
    V[b].emplace_back(a);
  }
  Dfs(1, 0);
  return printf("%d\n", col[1] && g[1] == 0 ? cnt : -1), 0;
}
