#include <bits/stdc++.h>
using namespace std;
const int N = 1e5;
vector<int> g[N];
int color[N], sub[N];
long long ans;
void dfs(int curr, int prev) {
  for (int next : g[curr])
    if (next != prev) {
      color[next] = color[curr] ^ 1;
      dfs(next, curr);
      sub[curr] += sub[next];
      ans += abs(sub[next]);
    }
  sub[curr] += color[curr] == 0 ? 1 : -1;
}
int main() {
  int n, m;
  cin >> n >> m;
  if (m != n - 1) return 0;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  dfs(0, -1);
  if (sub[0] != 0) ans = -1;
  cout << ans << endl;
}
