#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0},  {1, 1},   {0, 1},  {-1, 1},
                         {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};
const long double EPS = 0.0000001;
static int N, M;
static int a[100010], b[100010];
vector<int> G[100010];
static int c[100010], d[100010];
void dfs(int v, int p) {
  for (int i = 0; i < G[v].size(); i++) {
    int u = G[v][i];
    if (u == p) continue;
    dfs(u, v);
    d[v] += d[u];
    if (c[u] == 0) {
      d[v]++;
      c[v] ^= 1;
    }
  }
}
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 1; i <= M; i++) {
    scanf("%d%d", &a[i], &b[i]);
  }
  if (M == N) {
    return 0;
  }
  for (int i = 1; i <= M; i++) {
    G[a[i]].push_back(b[i]);
    G[b[i]].push_back(a[i]);
  }
  for (int i = 0; i < 100010; i++) {
    c[i] = 0;
    d[i] = 0;
  }
  dfs(1, 0);
  if (c[1] == 1)
    cout << d[1] << endl;
  else
    puts("-1");
}
