#include <bits/stdc++.h>
using namespace std;
const int N = 123456;
int n, m, s[N], value[N], answer;
vector<int> adj[N];
void dfs(int x, int f, int d) {
  for (auto y : adj[x]) {
    if (y != f) {
      dfs(y, x, !d);
      s[x] += s[y];
    }
  }
  s[x] += value[x];
  if (d) {
    ++s[x];
  } else {
    --s[x];
  }
  answer += abs(s[x]);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1, x, y; i <= m; ++i) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  if (m == n - 1) {
    dfs(1, 0, 0);
    cout << (s[1] ? -1 : answer) << '\n';
  }
  return 0;
}
