#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> G[100010];
bool col[100010];
int ans;
void dfs(int x, int p) {
  for (int i = 0; i < (int)G[x].size(); i++) {
    int y = G[x][i];
    if (y == p) continue;
    dfs(y, x);
  }
  if (!col[x]) col[x] ^= 1, col[p] ^= 1, ans++;
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  if (n == m)
    printf("-1");
  else {
    dfs(1, 0);
    if (col[0]) ans = -1;
    printf("%d", ans);
  }
  return 0;
}
