import std.algorithm;
import std.array;
import std.conv;
import std.stdio;
import std.string;

void main ()
{
	int n, m;
	while (readf (" %s %s", &n, &m) > 0)
	{
		debug {writefln ("n = %s, m = %s", n, m);}
		auto a = new int [] [n];
		foreach (j; 0..m)
		{
			int u, v;
			readf (" %s %s", &u, &v);
			u -= 1;
			v -= 1;
			a[u] ~= v;
			a[v] ~= u;
		}
		if (m != n - 1)
		{
			writeln (-1);
			continue;
		}

		auto c = new int [n];
		int res = 0;

		void recur (int v, int p)
		{
			debug {writeln (v, " ", p);}
			c[v] = 0;
			foreach (u; a[v])
			{
				if (u == p)
				{
					continue;
				}
				recur (u, v);
				if (!c[u])
				{
					c[u] ^= 1;
					c[v] ^= 1;
					res += 1;
				}
			}
		}

		recur (0, -1);
		if (!all (c))
		{
			res = -1;
		}
		writeln (res);
	}
}
