#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
using namespace std;

const int MAX_N = 1e5 + 5;
int n, m;
vector <int> G[MAX_N];

bool dfsTree (int v = 0, int p = 0) {
	int size = 1;
}

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int v, u;
		cin >> v >> u;
		v--, u--;

		G[v].push_back(u);
		G[u].push_back(v);
	}

	if (n & 1) {
		cout << "-1\n";
	}
	assert(false);

	if (n - 1 == m) {
		if (dfsTree())
			cout << (n >> 1) << "\n";
		else
			cout << "-1\n";
	}
	return 0;
}