#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T>
inline void chkmin(T&a, T b) { a = a < b ? a : b; }

const int MAXN = 100010;

int n;
int m;
int tot;
int fi[MAXN];
int to[MAXN << 1];
int ne[MAXN << 1];

inline void Link(int u, int v) {
	tot++;
	to[tot] = v;
	ne[tot] = fi[u];
	fi[u] = tot;
}

int col[MAXN];

inline ll Dfs(int x, int la, int d) {
	ll res = 0;
	col[x] = d;
	for(int i = fi[x]; i; i = ne[i]) {
		int u = to[i];
		if(u == la) continue;
		res += Dfs1(u, x, -d), col[x] += col[u];
	} return res + abs(col[x]);
}

int main() {
	n = ri, m = ri;

	if(n & 1) return puts("-1"), 0;

	for(int i = 1; i <= m; i++) {
		int u = ri, v = ri;
		Link(u, v), Link(v, u);
	}

	if(m == n - 1) return cout << Dfs(1, 0, 1) << endl, 0;

	return 0;
}