#include <bits/stdc++.h>
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define space putchar(' ')
#define enter putchar('\n')
#define eps 1e-10
#define MAXN 100005
//#define ivorysi
using namespace std;
typedef long long int64;
typedef unsigned int u32;
typedef double db;
template<class T>
void read(T &res) {
    res = 0;T f = 1;char c = getchar();
    while(c < '0' || c > '9') {
	if(c == '-') f = -1;
	c = getchar();
    }
    while(c >= '0' && c <= '9') {
	res = res * 10 +c - '0';
	c = getchar();
    }
    res *= f;
}
template<class T>
void out(T x) {
    if(x < 0) {x = -x;putchar('-');}
    if(x >= 10) {
	out(x / 10);
    }
    putchar('0' + x % 10);
}
struct node {
    int to,next;
}E[MAXN * 2];
int N,head[MAXN],sumE,M,fa[MAXN],dep[MAXN],st,ed;
int64 dp[MAXN][2],ans;
bool vis[MAXN];
int c[MAXN],tot,col[MAXN],rec[2],ned[MAXN];
pii val[MAXN];
vector<pii > f;
vector<int> dfn;
void add(int u,int v) {
    E[++sumE].to = v;
    E[sumE].next = head[u];
    head[u] = sumE;
}
void dfs(int u) {
    dp[u][0] = 1;
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(v != fa[u]) {
	    fa[v] = u;
	    dfs(v);
	    ans += dp[v][0] + dp[v][1];
	    dp[u][0] += dp[v][1];
	    dp[u][1] += dp[v][0];
	}
    }
    int t = min(dp[u][0],dp[u][1]);
    dp[u][0] -= t;dp[u][1] -= t;
}
void find_circle(int u) {
    dep[u] = dep[fa[u]] + 1;
    vis[u] = 1;
    dfn.pb(u);
    for(int i = head[u] ; i ; i = E[i].next) {
	int v = E[i].to;
	if(!vis[v]) {
	    fa[v] = u;
	    col[v] = col[u] ^ 1;
	    find_circle(v);
	}
	else if(dep[v] < dep[u] && v != fa[u]) {
	    
	    st = u;ed = v;
	}
    }
}
int64 Calc(int64 x) {
    int64 res = 0;
    for(auto t : f) {
	res += abs(t.fi * x + t.se);
    }
    return res;
}
void EvenCircle() {
    for(int i = dfn.size() - 1 ; i >= 0 ; --i) {
	int u = dfn[i];
	pii p = val[u];
	if(u == st) {
	    f.pb(mp(1,0));
	    p.fi -= 1;
	}
	else if(u == ed) p.fi += 1;
	if(col[u] == 0) p.se--;
	else p.se++;
	if(fa[u]) {
	    f.pb(p);
	    val[fa[u]].fi += p.fi;val[fa[u]].se += p.se;
	}
    }
    int64 L = -N,R = N;
    while(R - L >= 3) {
	int64 Lb = L + (R - L) / 3;
	int64 Rb = R - (R - L) / 3;
	if(Calc(Lb) > Calc(Rb)) L = Lb;
	else R = Rb;
    }
    int64 res = 1e18;
    for(int64 i = L ; i <= R ; ++i) res = min(res,Calc(i));
    out(res);enter;
}
void Calc_need(int u) {
    if(col[u]) ned[u] = -1;
    else ned[u] = 1;
    vis[u] = 1;
    for(int i = head[u] ; i ;  i = E[i].next) {
	int v = E[i].to;
	if(!vis[v]) {
	    Calc_need(v);
	    ans += abs(ned[v]);
	    ned[u] += ned[v];
	}
    }
}
void OddCircle() {
    int64 add = (rec[1] - rec[0]) / 2;
    memset(vis,0,sizeof(vis));
    for(int i = 1 ; i <= tot ; ++i) {
	vis[c[i]] = 1;
    }
    for(int i = 1 ; i <= tot ; ++i) {
	Calc_need(c[i]);
    }
    ned[c[1]] += add;
    ned[c[tot]] += add;
    for(int i = 2 ; i <= tot ; ++i) {
	ans += abs(ned[c[i - 1]]);
	ned[c[i]] += ned[c[i - 1]];
	ned[c[i - 1]] = 0;
    }
    for(int i = tot - 1 ; i >= 1 ; --i) {
	ans += abs(ned[c[i + 1]]);
	ned[c[i]] += ned[c[i + 1]];
    }
    out(ans + abs(add));enter;
}
void Process() {
    find_circle(1);
    for(int i = 1 ; i <= N ; ++i) {
	rec[col[i]]++;
    }
    int p = st;
    while(1) {
	c[++tot] = p;
	if(p == ed) break;
	p = fa[p];
    }
    if(tot % 2 == 0) {
	if(rec[0] != rec[1]) {puts("-1");return;}
	EvenCircle();
    }
    else {
	if((rec[0] ^ rec[1]) & 1) {puts("-1");return;}
	OddCircle();
    }
}
void Solve() {
    srand(time(0));
    read(N);read(M);
    int a,b;
    for(int i = 1 ; i <= M ; ++i) {
	read(a);read(b);
	add(a,b);add(b,a);
    }
    if(N & 1) {puts("-1");return;}
    if(M == N - 1) {
	dfs(1);
	if(dp[1][0] || dp[1][1]) {puts("-1");return;}
	out(ans);enter;
    }
    else Process();
}

int main() {
#ifdef ivorysi
    freopen("f1.in","r",stdin);
#endif
    Solve();
    return 0;
}


Measured memory_bytes: 10872