#include <bits/stdc++.h>
using namespace std;
const int N = 100005;
int n, m;
vector<int> adjlist[100005];
int U[N], V[N];
int a[N];
int num[N];
int p[N];
int col[N];
int ans = 0;
void dfs1(int u) {
  for (auto v : adjlist[u]) {
    if (col[v] == -1) {
      col[v] = 1 ^ col[u];
      num[v] = col[v] ? -1 : 1;
      p[v] = u;
      dfs1(v);
      num[u] += num[v];
    }
  }
  ans += abs(num[u]);
}
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &U[i], &V[i]);
    adjlist[U[i]].push_back(V[i]);
    adjlist[V[i]].push_back(U[i]);
  }
  memset(col, -1, sizeof(col));
  col[1] = 0;
  p[1] = 1;
  num[1] = 1;
  dfs1(1);
  if (num[1]) {
    printf("-1");
  } else
    printf("%d", ans);
}
