#include <bits/stdc++.h>
using namespace std;
const unsigned long long BIGEST = 1000000000000000000 + 1000000000000000000;
const long long BIGER = 1000000000000000000;
const int BIG = 1000000000;
const int MOD = 1000000007;
const long long LMOD = 1000000007;
vector<int> v[100001];
int f[100001];
int s = 0;
int ypa(int k, int p) {
  for (int i = 0; i < v[k].size(); i++) {
    if (v[k][i] == p) continue;
    ypa(v[k][i], k);
    f[k] += f[v[k][i]];
  }
  f[k] = -f[k] - 1;
  s += abs(f[k]);
  return 0;
}
int n, m;
int x, y;
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &x, &y);
    v[x].push_back(y);
    v[y].push_back(x);
  }
  ypa(1, 0);
  if (f[1] != 0) cout << "-1";
  cout << s;
  return 0;
}
