#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const long long INF = 0x7fffffffffffffff;
template <typename A, typename B>
ostream &operator<<(ostream &s, const pair<A, B> &p) {
  return s << "(" << p.first << "," << p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &s, const vector<T> &c) {
  s << "[ ";
  for (auto it : c) s << it << " ";
  s << "]";
  return s;
}
template <typename T>
ostream &operator<<(ostream &o, const set<T> &st) {
  o << "{";
  for (auto it = st.begin(); it != st.end(); it++)
    o << (it == st.begin() ? "" : ", ") << *it;
  return o << "}";
}
template <typename T1, typename T2>
ostream &operator<<(ostream &o, const map<T1, T2> &make_pair) {
  o << "{";
  for (auto it = make_pair.begin(); it != make_pair.end(); it++) {
    o << (it == make_pair.begin() ? "" : ", ") << it->first << ":"
      << it->second;
  }
  o << "}";
  return o;
}
int n, m;
vector<int> G[100005];
bool co[100005];
struct edge {
  int from, to;
};
vector<edge> e;
long long ans;
int dfs(int u, int p, int color) {
  int ret = color ? 1 : -1;
  for (int v : G[u])
    if (v != p) {
      ret += dfs(v, u, color ^ 1);
    }
  if (p != -1) ans += abs(ret);
  return ret;
}
int main() {
  cin >> n >> m;
  memset(co, (false), sizeof(co));
  ;
  if (m == n - 1) {
    for (int i = 0; i < m; i++) {
      int a, b;
      scanf("%d %d", &a, &b);
      a--, b--;
      G[a].push_back(b), G[b].push_back(a);
      e.push_back(edge{a, b});
    }
    assert(((int)(e).size()) == m);
    ans = 0;
    if (dfs(0, -1, 0))
      puts("-1");
    else
      printf("%lld\n", ans);
  } else
    puts("-1");
}
