#include <bits/stdc++.h>
using namespace std;
const int INF = 0x7fffffff;
const int MAXN = 1e5 + 3;
bool f[MAXN];
int n, m, t1, t2, ans, odd, even;
vector<int> g[MAXN];
void dfs(int x, int frm, int dep) {
  if (dep % 2) {
    odd++;
  } else {
    even++;
  }
  for (auto &i : g[x]) {
    if (i == frm) continue;
    dfs(i, x, dep + 1);
    if (!f[i]) {
      f[i] ^= 1;
      f[x] ^= 1;
      ans++;
    }
  }
}
void solve() {
  cin >> n >> m;
  if (n == m) {
    cout << "GG" << endl;
    exit(0);
  }
  for (int i = 0; i < (int)(m); i++) {
    cin >> t1 >> t2;
    g[t1].push_back(t2);
    g[t2].push_back(t1);
  }
  dfs(1, 0, 0);
  if (!f[1] || odd != even) {
    cout << -1 << endl;
    exit(0);
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  solve();
  cout << ans << endl;
  return 0;
}
