#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
long long n, m, ans;
vector<int> g[MAXN];
bool isc[MAXN];
pair<long long, long long> dfs(int v, int f = -1) {
  pair<long long, long long> tot = pair<long long, long long>(0, 0);
  for (int u : g[v]) {
    if (isc[u] || u == f) continue;
    pair<long long, long long> t = dfs(u, v);
    tot.first += t.first;
    tot.second += t.second;
  }
  if (tot.first >= tot.second)
    tot.first -= tot.second, tot.second = 0;
  else
    tot.second -= tot.first, tot.first = 0;
  if (tot.second >= 1)
    tot.second--;
  else
    tot.first++;
  ans += (tot.first + tot.second);
  swap(tot.first, tot.second);
  return tot;
}
int main() {
  cin >> n >> m;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  if (n % 2 == 1) {
    cout << "-1\n";
    return 0;
  }
  pair<long long, long long> t = dfs(0, -1);
  if (t != pair<long long, long long>(0, 0)) {
    cout << "-1\n";
    return 0;
  }
  cout << ans << endl;
}
