#include <bits/stdc++.h>
using namespace std;
template <class T>
void debug(T a, T b) {
  ;
}
template <class T>
void chmin(T& a, const T& b) {
  if (a > b) a = b;
}
template <class T>
void chmax(T& a, const T& b) {
  if (a < b) a = b;
}
namespace std {
template <class S, class T>
ostream& operator<<(ostream& out, const pair<S, T>& a) {
  out << '(' << a.first << ',' << a.second << ')';
  return out;
}
}  // namespace std
int n, m;
vector<int> g[100005];
void ng() {
  puts("-1");
  exit(0);
}
pair<long long int, long long int> dfs(int v, int p) {
  int cost = 0, flip = 0;
  for (auto to : g[v]) {
    if (to == p) continue;
    pair<long long int, long long int> nxt = dfs(to, v);
    cost += nxt.first;
    flip += nxt.second;
  }
  if (flip == 1)
    return make_pair(cost, 0);
  else
    return make_pair(cost + abs(flip - 1), 1 - flip);
}
void solve1() {
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  pair<long long int, long long int> res = dfs(0, -1);
  if (res.second) ng();
  printf("%lld\n", res.first);
}
struct uf {
  static const int MAXN = 100005;
  int par[MAXN];
  int size[MAXN];
  void init() {
    memset(par, -1, sizeof(par));
    for (int i = 0; i < (MAXN); ++i) size[i] = 1;
  }
  int root(int a) {
    if (par[a] == -1) return a;
    return par[a] = root(par[a]);
  }
  void unite(int a, int b) {
    a = root(a);
    b = root(b);
    if (a == b) return;
    if (size[a] < size[b]) swap(a, b);
    par[b] = a;
    size[a] += size[b];
  }
  bool same(int a, int b) { return root(a) == root(b); }
};
uf u;
vector<int> path, ever;
bool inCycle[100005];
void findpath(int a, int p, int b) {
  ever.push_back(a);
  if (a == b) {
    path = ever;
  }
  for (auto to : g[a]) {
    if (to == p) continue;
    findpath(to, a, b);
  }
  ever.pop_back();
}
pair<long long int, long long int> dfs2(int v, int p) {
  int cost = 0, flip = 0;
  for (auto to : g[v]) {
    if (to == p || inCycle[to]) continue;
    pair<long long int, long long int> nxt = dfs2(to, v);
    cost += nxt.first;
    flip += nxt.second;
  }
  if (flip == 1)
    return make_pair(cost, 0);
  else
    return make_pair(cost + abs(flip - 1), 1 - flip);
}
pair<long long int, long long int> es[100005];
void solve2() {
  u.init();
  for (int i = 0; i < (m); ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    es[i] = make_pair(a, b);
    if (u.same(a, b)) {
      findpath(a, -1, b);
    } else {
      u.unite(a, b);
      g[a].push_back(b);
      g[b].push_back(a);
    }
  }
  debug((path).begin(), (path).end());
  for (auto e : path) inCycle[e] = 1;
  for (int i = 0; i < (n); ++i) g[i].clear();
  for (int i = 0; i < (m); ++i) {
    int a = es[i].first, b = es[i].second;
    if (!inCycle[a] || !inCycle[b]) {
      g[a].push_back(b);
      g[b].push_back(a);
    }
  }
  long long int res = 0, sum = 0;
  vector<int> ar(path.size());
  for (int i = 0; i < (path.size()); ++i) {
    int v = path[i];
    pair<long long int, long long int> nxt = dfs2(v, -1);
    ;
    ;
    nxt.first -= abs(nxt.second);
    res += nxt.first;
    ar[i] = nxt.second;
    sum += ar[i];
  }
  if (sum & 1) ng();
  ;
  ;
  int n2 = ar.size();
  vector<int> prev = ar;
  debug((ar).begin(), (ar).end());
  for (int i = 0; i < (n2 - 1); ++i) {
    ar[i + 1] -= ar[i];
  }
  res += abs(ar[n2 - 1]) / 2;
  debug((ar).begin(), (ar).end());
  prev[0] += ar[n2 - 1] / 2 * (n2 & 1 ? -1 : 1);
  prev[n2 - 1] += ar[n2 - 1] / 2 * (n2 & 1 ? -1 : 1);
  ar = prev;
  debug((prev).begin(), (prev).end());
  for (int i = 0; i < (n2 - 1); ++i) {
    ar[i + 1] -= ar[i];
    res += abs(ar[i]);
    ;
    ;
  }
  assert(ar[n2 - 1] == 0);
  cout << res << endl;
}
int main() {
  cin >> n >> m;
  if (n & 1) ng();
  if (m == n - 1)
    solve1();
  else
    solve2();
  return 0;
}
