#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 1e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, m, token[maxn], cntToken[maxn], sz[maxn], DEPTH[maxn];
int cyclePar;
bool visited[maxn], cycleEdge[maxn];
vector<pair<int, int> > graph[maxn];
pair<int, int> CYCLEEDGE;

void getCycle(int u, int prev = -1)
{
	visited[u] = true;
	for (pair<int, int> i : graph[u])
	{
		if (!visited[i.ff])
		{
			getCycle(i.ff, u);
		}
		else if (i.ff != prev)
		{
			//cerr << "CYCLE EDGE " << u << ' ' << i.ff << endl;
			CYCLEEDGE = mp(u, i.ff);
			cycleEdge[i.ss] = true;
			cyclePar = (1 + DEPTH[i.ff] - DEPTH[u]) & 1;
		}
	}
}

void calcToken(int u, int depth = 0)
{
	DEPTH[u] = depth;
	visited[u] = true;
	sz[u] = 1;
	token[u] = (depth & 1 ? 1 : -1);
	cntToken[u] = token[u];
	for (auto i : graph[u])
	{
		if (!visited[i.ff] && !cycleEdge[i.ss])
		{
			calcToken(i.ff, depth + 1);
			sz[u] += sz[i.ff];
			cntToken[u] += cntToken[i.ff];
		}
	}
}

void getCntToken(int u)
{
	visited[u] = true;
	cntToken[u] = token[u];
	for (auto i : graph[u])
	{
		if (!visited[i.ff] && !cycleEdge[i.ss])
		{
			getCntToken(i.ff);
			cntToken[u] += cntToken[i.ff];
		}
	}
}

int solve(int u)
{
	visited[u] = true;
	int res = 0;
	for (auto i : graph[u])
	{
		if (!visited[i.ff] && !cycleEdge[i.ss])
		{
			//cerr << "SOLVE " << u << ':' << i.ff << ' ' << cntToken[i.ff] << endl;
			res += abs(cntToken[i.ff]);
			res += solve(i.ff);
		}
	}
	return res;
}

int SOLVE(int K)
{
	token[CYCLEEDGE.ff] -= K;
	token[CYCLEEDGE.ss] += K;

	memset(visited, false, sizeof(visited));
	getCntToken(0);
	memset(visited, false, sizeof(visited));
	int res = solve(0);

	token[CYCLEEDGE.ff] += K;
	token[CYCLEEDGE.ss] -= K;

	return res + abs(K);
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	cin >> n >> m;
	int u, v;
	for (int i = 0; i < m; i++)
	{
		cin >> u >> v;
		graph[--u].pb(mp(--v, i));
		graph[v].pb(mp(u, i));
	}

	calcToken(0);
	int cnt = 0;
	for (int i = 0; i < n; i++)
		cnt += (token[i] == 1);
	if (m == n - 1)
	{
		if ((n & 1) || cnt != n / 2)
		{
			cout << -1 << endl;
		}
		else
		{
			//cerr << "HERE" << endl;
			memset(visited, false, sizeof(visited));
			cout << solve(0) << endl;
		}
	}
	else
	{
		
		memset(visited, false, sizeof(visited));
		getCycle(0);
		
		memset(visited, false, sizeof(visited));
		calcToken(0);
		
		/*for (int i = 0; i < n; i++)
			cerr << '_' << token[i];
		cerr << endl;*/
		
		memset(visited, false, sizeof(visited));
		if (cyclePar & 1)
		{
			if ((cnt & 1) != ((n - cnt) & 1))
			{
				cout << -1 << endl;
			}
			else
			{
				int K = ((n - cnt) - cnt) / 2;
				for (int i = 0; i < n; i++)
					for (auto j : graph[i])
					{
						if (cycleEdge[j.ss])
						{
							token[j.ff] += K;
						}
					}
				/*for (int i = 0; i < n; i++)
					cerr << '_' << token[i];
				cerr << endl;*/
				memset(visited, false, sizeof(visited));
				getCntToken(0);

				/*for (int i = 0; i < n; i++)
					cerr << '_' << cntToken[i];
				cerr << endl;*/
				
				//cerr << "ODD HERE " << K << endl;
				memset(visited, false, sizeof(visited));
				cout << solve(0) + abs(K) << endl;
			}
		}
		else
		{
			//while (true)
			//	n++;
			if ((n & 1) || cnt != n / 2)
			{
				cout << -1 << endl;
			}
			else
			{
				int l = -maxn, r = maxn, mid;
				while (r - l > 4)
				{
					mid = (l + r) / 2;
					int val1 = SOLVE(mid), val2 = SOLVE(mid + 1);
					if (val1 == val2)
						l = mid, r = mid + 1;
					else if (val1 < val2)
						r = mid + 1;
					else
						l = mid;
				}
				int ans = mod;
				for (int i = l; i <= r; i++)
					ans = min(ans, SOLVE(i));
				cout << ans << endl;
			}
		}
	}
}



Measured memory_bytes: 12160