#include <bits/stdc++.h>
using namespace std;
int N, M, ans = 0;
vector<int> adj[100010];
pair<int, int> dfs(int u, int p, int d) {
  if (p != -1 && adj[u].size() == 1) {
    ans++;
    return pair<int, int>(d, 1);
  }
  int acnt = d ? 1 : 0;
  int bcnt = d ? 0 : 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == p) continue;
    pair<int, int> t = dfs(v, u, d ^ 1);
    if (t.first)
      acnt += t.second;
    else
      bcnt += t.second;
  }
  if (acnt <= bcnt) {
    ans += bcnt - acnt;
    return pair<int, int>(0, bcnt - acnt);
  } else {
    ans += acnt - bcnt;
    return pair<int, int>(1, acnt - bcnt);
  }
}
int main() {
  scanf("%d %d", &N, &M);
  for (int i = 0; i < M; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  pair<int, int> t = dfs(0, -1, 0);
  if (t.second)
    printf("-1");
  else
    printf("%d", ans);
}
