#include <bits/stdc++.h>
static std::istream& ip = std::cin;
static std::ostream& op = std::cout;
using namespace std;
struct Node {
  vector<int> neighbors;
  bool has;
} nodes[100010];
int n, m;
pair<int, int> e[100010];
int chas;
int rst;
void SetHas(int id, int fatherid, bool has) {
  if (has) ++chas;
  nodes[id].has = has;
  for (auto nb : nodes[id].neighbors) {
    if (nb == fatherid) continue;
    SetHas(nb, id, !has);
  }
}
int GetMoveIn(int id, int fatherid) {
  int tatal_in = 0;
  for (auto nb : nodes[id].neighbors) {
    if (nb == fatherid) continue;
    int t = GetMoveIn(nb, id);
    tatal_in += t;
    rst += ((t) > 0 ? (t) : -(t));
  }
  if (nodes[id].has) {
    return tatal_in + 1;
  } else {
    return tatal_in - 1;
  }
}
int main(int argc, char* argv[]) {
  ;
  ip >> n >> m;
  for (int i = 0; i < m; ++i) {
    ip >> e[i].first >> e[i].second;
  }
  if (n == m + 1) {
    chas = 0;
    for (int i = 0; i < m; ++i) {
      int a = e[i].first;
      int b = e[i].second;
      nodes[a].neighbors.push_back(b);
      nodes[b].neighbors.push_back(a);
    }
    SetHas(1, 0, false);
    if (chas * 2 != n)
      rst = -1;
    else {
      rst = 0;
      if (GetMoveIn(1, 0) != 0) throw "Error";
    }
    op << rst << endl;
  }
  return 0;
}
