#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<int> u[100005];
int oc[100005][2];
int o(int i, int p, int dp) {
  if (oc[i][dp] != -1) return oc[i][dp];
  int &res = oc[i][dp];
  res = 1e8;
  int mc[2];
  mc[0] = 0;
  mc[1] = 1e8;
  for (int j : u[i])
    if (j != p) {
      int te = o(j, i, 0) + 1;
      int dt = o(j, i, 1);
      int nm0 = min(mc[0] + dt, mc[1] + te);
      int nm1 = min(mc[1] + dt, mc[0] + te);
      nm0 = min(nm0, (int)1e8);
      nm1 = min(nm1, (int)1e8);
      mc[0] = nm0;
      mc[1] = nm1;
    }
  return res = mc[dp];
}
int main() {
  scanf("%d %d", &n, &m);
  assert(m == n - 1);
  for (int i = (0); i < (m); i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    x--;
    y--;
    u[x].emplace_back(y);
    u[y].emplace_back(x);
  }
  memset(oc, -1, sizeof oc);
  int res = o(0, -1, 1);
  if (res < 1e7)
    printf("%d\n", res);
  else
    printf("-1\n");
}
