#include <bits/stdc++.h>
using namespace std;
const int INF = 1012345678;
vector<int> AdjList[100005];
vector<int> AdjList2[100005];
bool visited[100005];
int p[100005];
void dfs(int u, int p2) {
  if (visited[u]) {
    return;
  }
  visited[u] = true;
  if (p2 != -1) {
    AdjList2[p2].push_back(u);
  }
  p[u] = p2;
  for (int v : AdjList[u]) {
    dfs(v, u);
  }
}
map<tuple<int, int, int>, int> memo;
int dp(int u, int childIndx, int u_state) {
  long long ans = 0;
  int size1 = (int)AdjList2[u].size();
  if (size1 == childIndx) {
    if (u_state == 1) {
      return 0;
    } else {
      return INF;
    }
  } else if (memo.find(tuple<int, int, int>(u, childIndx, u_state)) !=
             memo.end()) {
    return memo[tuple<int, int, int>(u, childIndx, u_state)];
  } else {
    int child = AdjList2[u][childIndx];
    ans = min(1 + dp(u, childIndx + 1, u_state ^ 1) + dp(child, 0, 1),
              dp(u, childIndx + 1, u_state) + dp(child, 0, 0));
  }
  return memo[tuple<int, int, int>(u, childIndx, u_state)] =
             min(ans, (long long)INF);
}
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  assert(M == N - 1);
  for (int i = 0; i < M; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    AdjList[x].push_back(y);
    AdjList[y].push_back(x);
  }
  memset(visited, 0, sizeof(visited));
  dfs(1, -1);
  int ans = dp(1, 0, 0);
  if (ans >= INF) {
    ans = -1;
  }
  printf("%d", ans);
  return 0;
}
