#include <bits/stdc++.h>
using namespace std;
vector<int> g[100010];
int col[100010], opt[100010];
int ans;
void dfs(int x, int par) {
  opt[x] = 1;
  for (auto i : g[x]) {
    if (i == par) continue;
    dfs(i, x);
    opt[x] -= opt[i];
  }
  ans += abs(opt[x]);
}
int main(int argc, char const *argv[]) {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= m; i++) {
    int p, q;
    scanf("%d %d", &p, &q);
    g[p].push_back(q);
    g[q].push_back(p);
  }
  dfs(1, 0);
  if (opt[1] == 0) {
    printf("%d\n", ans);
  } else
    printf("-1\n");
  return 0;
}
