#include <bits/stdc++.h>
using namespace std;
vector<int> g[101010];
const long long inf = 1e17;
long long dp[101010][2];
void dfs(int x, int p) {
  vector<long long> ch;
  long long bc = 0;
  for (int nx : g[x]) {
    if (nx != p) {
      dfs(nx, x);
      bc += dp[nx][1];
      ch.push_back(dp[nx][0] - dp[nx][1]);
    }
  }
  dp[x][0] = bc;
  sort(ch.begin(), ch.end());
  for (int i = 0; i < (int)ch.size(); i++) {
    bc += ch[i];
    if (i % 2 == 0) {
      dp[x][1] = min(dp[x][1], bc + (long long)i + 1ll);
    } else {
      dp[x][0] = min(dp[x][0], bc + (long long)i + 1ll);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  assert(m == n - 1);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  for (int i = 1; i <= n; i++) {
    dp[i][0] = inf;
    dp[i][1] = inf;
  }
  dfs(1, 0);
  if (dp[1][1] < inf) {
    cout << dp[1][1] << endl;
  } else {
    cout << -1 << endl;
  }
}
