#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int SIZE = 1e6 + 10;
vector<int> e[SIZE];
long long an;
pair<long long, long long> dfs(int x, int lt) {
  pair<long long, long long> need = make_pair(0, 0);
  for (int i = 0; i < (((int)(e[x]).size())); ++i) {
    if (e[x][i] == lt) continue;
    pair<long long, long long> r = dfs(e[x][i], x);
    need.first += r.first, need.second += r.second;
  }
  if (need.first > need.second) {
    an += need.first - 1 - need.second;
    return make_pair(0, need.first - 1 - need.second);
  } else {
    an += need.second - need.first + 1;
    return make_pair(need.second - need.first + 1, 0);
  }
}
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  if (n == m) return 0;
  for (int i = 0; i < (m); ++i) {
    int x, y;
    scanf("%d%d", &x, &y);
    x--, y--;
    e[x].push_back(y);
    e[y].push_back(x);
  }
  pair<long long, long long> r = dfs(0, 0);
  if (r.first != r.second) an = -1;
  cout << an << endl;
  return 0;
}
