#include <bits/stdc++.h>
using namespace std;
int N, M;
vector<vector<int> > G, T;
long long res;
void build(int a, int b) {
  for (int i = 0; i < G[a].size(); i++) {
    int c = G[a][i];
    if (c == b) continue;
    T[a].push_back(c);
    build(c, a);
  }
  return;
}
int cal(int a) {
  int now = 1;
  for (int i = 0; i < T[a].size(); i++) {
    now -= cal(T[a][i]);
  }
  if (a != 1) {
    res += abs(now);
  }
  return now;
}
int main() {
  ios::sync_with_stdio(false);
  cin >> N >> M;
  if (N == M) {
    cout << -1 << endl;
    return 0;
  }
  G.resize(N + 1);
  T.resize(N + 1);
  int a, b;
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  build(1, 0);
  res = 0;
  int ok = cal(1);
  if (ok != 0)
    cout << -1 << endl;
  else
    cout << res << endl;
  return 0;
}
