#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007ll;
const double EPS = 1e-11;
int n, m;
vector<int> g[125252];
int deg[125252];
bool used[125252];
pair<long long, long long> dfs(int p) {
  used[p] = true;
  pair<long long, long long> ret = pair<long long, long long>(0, 0);
  for (int i = 0; i < (int)(g[p].size()); ++i) {
    int to = g[p][i];
    if (used[to]) continue;
    pair<long long, long long> tmp = dfs(to);
    ret.first += tmp.first;
    ret.second += tmp.second;
  }
  ret.first += abs(ret.second - 1);
  ret.second = 1 - ret.second;
  return ret;
}
int main() {
  scanf("%d%d", &n, &m);
  assert(m == n - 1);
  for (int i = 0; i < (int)(m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
    deg[a]++;
    deg[b]++;
  }
  int cnt = count(deg, deg + n, 1);
  if (n > 2 && cnt == n - 1) {
    puts("-1");
    return 0;
  }
  if (n % 2 == 1) {
    puts("-1");
    return 0;
  }
  long long ans = dfs(0).first;
  printf("%lld\n", ans);
  return 0;
}
