// by desert97, https://beta.atcoder.jp/contests/agc004/submissions/1815397
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pii;

#define A first
#define B second

const int MAXN = 1e5+5;

ll n, m, ans;
vector<int> g[MAXN];
bool isc[MAXN];
int deg[MAXN];
int p[MAXN];
vector<int> gg[MAXN];
vector<int> c, d;

pii dfs(int v, int f = -1) {
	pii tot = pii(0, 0);
	for (int u : g[v]) {
		if (isc[u] || u == f)
			continue;
		pii t = dfs(u, v);
		tot.A += t.A;
		tot.B += t.B;
	}

	if (tot.A >= tot.B)
		tot.A -= tot.B, tot.B = 0;
	else
		tot.B -= tot.A, tot.A = 0;

	if (tot.B >= 1)
		tot.B--;
	else
		tot.A++;

	if (!isc[v])
		ans += (tot.A + tot.B);
	swap(tot.A, tot.B);
	return tot;
}

void findc() {
	set<pii> s;
	for (int i = 0; i < n; ++i) {
		deg[i] = g[i].size();
		s.insert(pii(deg[i], i));
		// cout << i << ' ' << deg[i] << endl;
	}

	while (!s.empty()) {
		pii t = (*s.begin());
		// cout << t.B << endl;
		if (t.A == 2)
			break;
		s.erase(t);
		for (int u : g[t.B]) {
			s.erase(pii(deg[u], u));
			deg[u]--;
			if (deg[u] != 0)
				s.insert(pii(deg[u], u));
		}
	}

	for (pii t : s)
		isc[t.B] = 1;
}

void dfsc(int v, int f = -1) {
	d.push_back(v);
	if (gg[v][0] != f && gg[v][0] != d[0]) {
		dfsc(gg[v][0], v);
	} else if (gg[v][1] != f && gg[v][1] != d[0]) {
		dfsc(gg[v][1], v);
	}
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		g[a].push_back(b);
		g[b].push_back(a);
	}

	if (m == n-1) {
		g[0].push_back(g[0][0]);
		g[g[0][0]].push_back(0);
	}

	if (n%2 == 1) {
		cout << "-1\n";
		return 0;
	}

	findc();

	for (int i = 0; i < n; ++i)
		if (isc[i]) {
			c.push_back(i);
			pii t = dfs(i, -1);
			p[i] = t.A - t.B;
		}

	for (int i : c)
		for (int j : g[i])
			if (isc[j])
				gg[i].push_back(j);

	dfsc(c[0]);
	c = d;

	if (c.size()%2 == 1) {
		ll x = 0;
		for (int i : c)
			x = -x + p[i];
		x /= 2;
		ans += abs(x);
		for (int i = 0; i < c.size()-1; ++i) {
			x = -x + p[c[i]];
			ans += abs(x);
		}

		cout << ans << endl;
	} else {
		ll s1 = 0, s2 = 0;
		for (int i = 0; i < c.size(); i += 2)
			s1 += p[c[i]], s2 += p[c[i+1]];
		if (s1 != s2) {
			cout << "-1\n";
			return 0;
		}

		vector<int> b;
		b.push_back(0);
		ll x = 0;

		for (int i = 0; i < c.size()-1; ++i) {
			x = -x + p[c[i]];
			if (i%2 == 0)
				b.push_back(-x);
			else
				b.push_back(x);
		}

		sort(b.begin(), b.end());
		for (int i = 0; i < c.size()/2; ++i)
			ans += b[i+c.size()/2] - b[i];
		cout << ans << endl;
	}
}
/*
#include<stdio.h>
#include<algorithm>
#include<map>
#include<string.h>
#include<vector>
#include<math.h>
#include<stdlib.h>
#include<set>
#include<ctype.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;

const int MM = 1000000007;
const int MX = 100005;

vector<int> T[MX];
ll G[MX], cnt[MX];
int N, M;

void dfs(int x, int lv= 0, int p = -1){
if( lv&1 ) cnt[x] = 1;
else cnt[x] = -1;
for(int c : T[x]){
if( c == p ) continue;
dfs(c, lv+1, x);
cnt[x] += cnt[c];
G[x] += G[c];
}
G[x] += abs(cnt[x]);
}

int main()
{
scanf("%d%d", &N, &M);
if( N == M) return 0;
for(int i = 1; i <= M; i++){
int a, b;
scanf("%d%d", &a, &b);
T[a].push_back(b);
T[b].push_back(a);
}
dfs(1);
if( cnt[1] != 0 ) printf("-1\n");
else printf("%lld\n", G[1]);
}
 */


Measured memory_bytes: 22784