#include <bits/stdc++.h>
using namespace std;
const int N = (1 << 17);
int n, m, ans, cnt;
int db[N], dw[N];
vector<int> g[N];
void dive(int u, int p, int cc) {
  cnt += cc;
  db[u] = 1;
  for (auto v : g[u]) {
    if (v != p) {
      dive(v, u, -cc);
      ans -= db[u] + dw[u];
      if (db[v] > dw[v])
        dw[u] += db[v] - dw[v];
      else
        db[u] += dw[v] - db[v];
      ans += db[u] + dw[u];
    }
  }
}
int main() {
  cin >> n >> m;
  if (m != n - 1) {
    cout << -1;
    return 0;
  }
  for (int i = 0; i < m; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dive(0, -1, 1);
  if (cnt != 0)
    cout << -1;
  else
    cout << ans;
}
