#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n, m;
vector<int> g[100000];
int d[100000];
long long sum = 0;
long long ans = INF;
void dfs(int v, int par) {
  d[v] = 1;
  for (int to : g[v])
    if (to != par) {
      dfs(to, v);
      d[v] -= d[to];
    }
  sum += abs(d[v]);
}
inline void change(int &x, int y) {
  sum -= abs(x);
  x = y;
  sum += abs(x);
}
void solve(int v, int par) {
  if (d[v] == 0) {
    ans = min(ans, sum);
  }
  for (int to : g[v])
    if (to != par) {
      change(d[v], d[v] + d[to]);
      change(d[to], d[to] - d[v]);
      solve(to, v);
      change(d[to], d[to] + d[v]);
      change(d[v], d[v] - d[to]);
    }
}
int main() {
  scanf("%d%d", &n, &m);
  if (m != n - 1) {
    return 0;
  }
  for (int i = 0; i < (int)(m); ++i) {
    int from, to;
    scanf("%d%d", &from, &to), --from, --to;
    g[from].push_back(to);
    g[to].push_back(from);
  }
  dfs(0, -1);
  solve(0, -1);
  if (ans == INF) {
    ans = -1;
  }
  cout << ans << endl;
  return 0;
}
