#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int inf = 1e9;
int n, m;
vector<int> way[maxn];
int dp[maxn][2], tmp[2];
void solve(int u, int last) {
  for (auto v : way[u]) {
    if (v == last) continue;
    solve(v, u);
  }
  dp[u][1] = 0;
  dp[u][0] = inf;
  for (auto v : way[u]) {
    if (v == last) continue;
    tmp[0] = min(dp[u][0] + dp[v][0], dp[u][1] + dp[v][1] + 1);
    tmp[1] = min(dp[u][0] + dp[v][1] + 1, dp[u][1] + dp[v][0]);
    dp[u][0] = tmp[0];
    dp[u][1] = tmp[1];
  }
}
int main() {
  scanf("%d%d", &n, &m);
  assert(n == m + 1);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    way[u].push_back(v);
    way[v].push_back(u);
  }
  solve(1, 0);
  if (dp[1][0] > n - 1)
    printf("-1");
  else
    printf("%d", dp[1][0]);
}
