// Namori
// * frank_c1
// * 2017 / 12 / 18
 
#include <bits/stdc++.h>
using namespace std;

const int maxn = (int)(1e5) + 5;
vector<int> nxt[maxn];
int fa[maxn], dfn[maxn], siz[maxn], su[maxn];
int ci[maxn], cc[maxn], va[maxn];
int cnt, idx, S, T;

inline int iabs(int x) {
	return x >= 0 ? x : -x;
}

void dfs(int x, int f, int v) {
	fa[x] = f; dfn[x] = ++idx; 
	siz[x] = 1; su[x] = v; v ^= 1;
	for (int i = 0; i < (int)nxt[x].size(); ++i)
		if (nxt[x][i] != f) {
			if (!dfn[nxt[x][i]]) {
				dfs(nxt[x][i], x, v);
				su[x] += su[nxt[x][i]];
				siz[x] += siz[nxt[x][i]];
			} else if (dfn[nxt[x][i]] < dfn[x]) {
				int c = x, a = nxt[x][i]; 
				while (c != a) {
					ci[++cnt] = c; cc[c] = 1; c = fa[c];
				} ++cnt; S = x; T = a;
			}
		}
}

int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; ++i) {
		int u, v;
		scanf("%d%d", &u, &v);
		nxt[u].push_back(v); nxt[v].push_back(u);
	}
	dfs(1, 0, 0);
	if (!cnt || !(cnt & 1)) {
		if (2 * su[1] != siz[1]) {
			printf("-1\n"); return 0;
		}
	} else {
		if ((2 * su[1] - siz[1]) & 1) {
			printf("-1\n"); return 0;
		}
	}
	int dt = (2 * su[1] - siz[1]) / 2, ret = iabs(dt);
	if (cnt & 1) {
		while (S != T) {
			siz[S] += dt; cc[S] = 0; S = fa[S];
		}
		while (T) {
			siz[T] += dt * 2; T = fa[T];
		} 
	}
	for (int i = 1; i <= n; ++i) if (!cc[i]) ret += iabs(2 * su[i] - siz[i]);
	if (!(cnt & 1)) {
		for (int i = 1; i < cnt; ++i) va[i] = 2 * su[ci[i]] - siz[ci[i]];
		va[cnt] = 0; sort(va + 1, va + cnt + 1); ret += iabs(va[(cnt + 1) / 2]); 
		for (int i = 1; i < cnt; ++i) ret += iabs(va[(cnt + 1) / 2] - 2 * su[ci[i]] + siz[ci[i]]);
	}
	printf("%d\n", ret);
	return 0;
}