#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef vector<int> V;

int n, m;
int a[100000];
int b[100000];
V t[100000];
bool u[100000];
int s;

int dfs(int x){
	u[x] = true;
	int k = 1;
	for(int i: t[x]){
		if(!u[i]){
			k += dfs(i);
		}
	}
	k %= 2;
	if(x){
		s += k;
	}
	else if(k){
		s = -1;
	}
	return k;
}

int main(){
	cin >> n >> m;
	rep(i, m){
		cin >> a[i] >> b[i];
		--a[i];
		--b[i];
	}

	if(m > n){
		cout << -1 << endl;
	}

	rep(i, n - 1){
		t[a[i]].push_back(b[i]);
		t[b[i]].push_back(a[i]);
	}
	dfs(0);
	cout << s << endl;
	return 0;
}