#include <bits/stdc++.h>
using namespace std;
vector<int> gr[114514];
int pat[114514], st[114514], go[114514];
int num[3];
int out = 0;
void dfs(int v, int p) {
  if (pat[v] >= 0) return;
  pat[v] = p;
  num[pat[v]]++;
  for (int i = 0; i < gr[v].size(); i++) {
    int w = gr[v][i];
    dfs(w, 1 - p);
  }
}
void dfs2(int v, int u) {
  st[v] = go[v] = 0;
  for (int i = 0; i < gr[v].size(); i++) {
    int w = gr[v][i];
    if (w == u) continue;
    dfs2(w, v);
    out += abs(st[w] - go[w]);
    st[v] += st[w];
    go[v] += go[w];
  }
  if (pat[v] == 1)
    st[v]++;
  else
    go[v]++;
}
int main() {
  int n, m, a, b;
  scanf("%d %d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d %d", &a, &b);
    a--;
    b--;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  memset(num, 0, sizeof(num));
  memset(pat, -1, sizeof(pat));
  dfs(0, 0);
  if (num[0] != num[1]) {
    cout << -1 << endl;
    return 0;
  }
  dfs2(0, -1);
  cout << out << endl;
}
