#include <bits/stdc++.h>
using namespace std;
const long double EPS = (long double)1e-7;
const long double PI = acos(0) * 2;
bool isZero(const long double& x) { return abs(x) <= EPS; }
int sign(const long double& x) { return isZero(x) ? 0 : (0 < x ? 1 : -1); }
long long gcd(long long a, long long b) {
  for (; b; a %= b, swap(a, b)) {
  }
  return abs(a);
}
pair<long long, long long> operator+(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return pair<long long, long long>(a.first + b.first, a.second + b.second);
}
pair<long long, long long> operator-(const pair<long long, long long>& a,
                                     const pair<long long, long long>& b) {
  return pair<long long, long long>(a.first - b.first, a.second - b.second);
}
pair<long long, long long> operator*(const pair<long long, long long>& a,
                                     const long long& b) {
  return pair<long long, long long>(a.first * b, a.second * b);
}
long long operator*(const pair<long long, long long>& a,
                    const pair<long long, long long>& b) {
  return a.first * b.second - b.first * a.second;
}
long long ccw(const pair<long long, long long>& a,
              const pair<long long, long long>& b,
              const pair<long long, long long>& c) {
  return a * b + b * c + c * a;
}
int rd(int s, int e) { return rand() % (e - s + 1) + s; }
void fg(vector<int> G[], int a, int b) {
  G[a].push_back(b);
  G[b].push_back(a);
}
void fg(vector<pair<int, int> > G[], int a, int b, int c) {
  G[a].push_back({b, c});
  G[b].push_back({a, c});
}
const int MAXN = 100005;
const int MAXM = 100005;
vector<int> G[MAXN];
int dep[MAXN], dpu[MAXN], dpc[MAXN];
int A[MAXM], B[MAXM];
int N, M;
void f(int idx, int depth) {
  dep[idx] = depth;
  for (int v : G[idx])
    if (!dep[v]) {
      f(v, depth + 1);
      dpc[idx] += dpc[v];
      dpu[idx] += dpu[v];
    }
  dpc[idx] += dpu[idx];
  dpu[idx] = (dpu[idx] + 1) & 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M;
  for (int i = 1; i <= M; i++) {
    cin >> A[i] >> B[i];
    fg(G, A[i], B[i]);
  }
  f(1, 1);
  if (dpu[1])
    puts("-1");
  else
    printf("%d\n", dpc[1]);
  return 0;
}
