#include <bits/stdc++.h>
using namespace std;
double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1, 0, 0, 1, -1, -1, 1, 1};
int diry[8] = {0, 1, -1, 0, -1, 1, -1, 1};
inline string IntToString(long long a) {
  char x[100];
  sprintf(x, "%lld", a);
  string s = x;
  return s;
}
inline long long StringToInt(string a) {
  char x[100];
  long long res;
  strcpy(x, a.c_str());
  sscanf(x, "%lld", &res);
  return res;
}
inline string GetString(void) {
  char x[1000005];
  scanf("%s", x);
  string s = x;
  return s;
}
inline string uppercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}
inline string lowercase(string s) {
  int n = (int)s.size();
  for (int(i) = (0); (i) < (n); ++(i))
    if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}
inline void OPEN(string s) {
  freopen((s + ".in").c_str(), "r", stdin);
  freopen((s + ".out").c_str(), "w", stdout);
}
int n, m;
vector<int> adj[100005];
int a, b;
queue<int> q;
int warna[100005];
int parent[100005];
int child[100005];
void dfs(int x) {
  for (int(i) = (0); (i) < ((int)adj[x].size()); ++(i)) {
    if (parent[adj[x][i]] == -1) {
      parent[adj[x][i]] = x;
      dfs(adj[x][i]);
      ++child[x];
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int(i) = (0); (i) < (m); ++(i)) {
    scanf("%d %d", &a, &b);
    --a;
    --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  memset(parent, -1, sizeof(parent));
  parent[0] = 0;
  dfs(0);
  for (int(i) = (0); (i) < (n); ++(i)) {
    if (child[i] == 0) q.push(i);
  }
  int risan = 0;
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    if (warna[x]) continue;
    if (child[x] > 0) continue;
    if (x == 0) {
      puts("-1");
      return 0;
    }
    warna[x] = 1 - warna[x];
    warna[parent[x]] = 1 - warna[parent[x]];
    if (x > 0 && warna[x]) --child[parent[x]];
    if (x > 0 && !warna[x]) ++child[parent[x]];
    if (x > 0 && child[parent[x]] == 0) q.push(parent[x]);
    if (parent[x] > 0 && warna[parent[x]]) --child[parent[parent[x]]];
    if (parent[x] > 0 && !warna[parent[x]]) ++child[parent[parent[x]]];
    if (parent[x] > 0 && child[parent[parent[x]]] == 0)
      q.push(parent[parent[x]]);
    ++risan;
  }
  printf("%d\n", risan);
  return 0;
}
