#include <bits/stdc++.h>
using namespace std;
const long long UNDEF = -1;
const long long INF = 1e18;
template <typename T>
inline bool chkmax(T &aa, T bb) {
  return aa < bb ? aa = bb, true : false;
}
template <typename T>
inline bool chkmin(T &aa, T bb) {
  return aa > bb ? aa = bb, true : false;
}
const long long mn = 1e5 + 4;
vector<long long> g[mn];
long long dp[mn][2];
void f(long long x, long long p) {
  long long h0 = 0, h1 = INF;
  for (auto &y : g[x]) {
    if (y == p) continue;
    f(y, x);
    long long nh0 = min(h0 + dp[y][0], h1 + dp[y][1] + 1);
    long long nh1 = min(h0 + dp[y][1] + 1, h1 + dp[y][0]);
    h0 = nh0, h1 = nh1;
  }
  dp[x][1] = h0, dp[x][0] = h1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long n, m;
  cin >> n >> m;
  if (m != n - 1) {
    cout << -1 << "\n";
    return 0;
  }
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  f(1, -1);
  long long ans = dp[1][0];
  if (ans >= INF) ans = -1;
  cout << ans << "\n";
}
