/*ID:PROG:LANG:*/
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 998244353
#define MAXN 100005
using namespace std;
struct Edge{
	int to,nex;Edge(int _=0,int __=0){to=_,nex=__;}
}e[MAXN<<1];
int n,m,ans,s,t,Top,cnt,hd[MAXN],dep[MAXN],dp[MAXN],fa[MAXN],q[MAXN];
int rd(){
	int x=0,tp=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x*10+c-'0');c=getchar();}
	return x*tp;
}
void adde(int x,int y){e[++cnt]=Edge(y,hd[x]);hd[x]=cnt;}
void dfs(int now,int f){
	dep[now]=dep[f]+1,fa[now]=f;
	dp[now]=(dep[now]%2)?1:-1;
	for(int i=hd[now];i;i=e[i].nex){
		if(e[i].to!=f){
			if(dep[e[i].to]){
				s=now,t=e[i].to;
				continue;
			}
			dfs(e[i].to,now);
			dp[now]+=dp[e[i].to];
		}
	}
}
void get_tree_ans(){
	if(dp[1]){printf("-1\n");exit(0);}
	for(int i=1;i<=n;i++)ans+=abs(dp[i]);
	printf("%d\n",ans);
}
void jihuan(){
	if(dp[1]%2){printf("-1\n");exit(0);}
	int tmp=-dp[1]/2;
	ans=abs(tmp);
	for(int i=s;i;i=fa[i])dp[i]+=tmp;
	for(int i=t;i;i=fa[i])dp[i]+=tmp;
	for(int i=1;i<=n;i++)ans+=abs(dp[i]);
	printf("%d\n",ans);
}
void ouhuan(){
	if(dp[1]){printf("-1\n");exit(0);}
	for(int i=t;i!=s;i=fa[i])q[++Top]=dp[i],dep[i]=0;
	sort(q+1,q+Top+1);
	int mid=q[(Top+1)/2];
	ans=abs(mid);
	for(int i=1;i<=n;i++)if(dep[i])ans+=abs(dp[i]);
	for(int i=1;i<=Top;i++)ans+=abs(q[i]-mid);
	printf("%d\n",ans);
}
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("1.out","w",stdout);
	int x,y;
	n=rd(),m=rd();
	for(int i=1;i<=m;i++){
		x=rd(),y=rd();
		adde(x,y),adde(y,x);
	}
	dfs(1,0);
	if(m==n-1){get_tree_ans();return 0;}
	if((dep[t]-dep[s])%2==0)jihuan();
	else ouhuan();
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}
### Prompt

In CPP, your task is to solve the following problem:

You are given an undirected graph with N vertices and M edges. Here, N-1≤M≤N holds and the graph is connected. There are no self-loops or multiple edges in this graph.

The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects vertices a_i and b_i.

The color of each vertex can be either white or black. Initially, all the vertices are white. Snuke is trying to turn all the vertices black by performing the following operation some number of times:

* Select a pair of adjacent vertices with the same color, and invert the colors of those vertices. That is, if the vertices are both white, then turn them black, and vice versa.



Determine if it is possible to turn all the vertices black. If the answer is positive, find the minimum number of times the operation needs to be performed in order to achieve the objective.

Constraints

* 2≤N≤10^5
* N-1≤M≤N
* 1≤a_i,b_i≤N
* There are no self-loops or multiple edges in the given graph.
* The given graph is connected.

Input

The input is given from Standard Input in the following format:


N M
a_1 b_1
a_2 b_2
:
a_M b_M


Output

If it is possible to turn all the vertices black, print the minimum number of times the operation needs to be performed in order to achieve the objective. Otherwise, print `-1` instead.

Examples

Input

6 5
1 2
1 3
1 4
2 5
2 6


Output

5


Input

3 2
1 2
2 3


Output

-1


Input

4 4
1 2
2 3
3 4
4 1


Output

2


Input

6 6
1 2
2 3
3 1
1 4
1 5
1 6


Output

7

### Response

```cpp
/*ID:PROG:LANG:*/
#include<bits/stdc++.h>
#define LL long long
#define INF 0x3f3f3f3f
#define MOD 998244353
#define MAXN 100005
using namespace std;
struct Edge{
	int to,nex;Edge(int _=0,int __=0){to=_,nex=__;}
}e[MAXN<<1];
int n,m,ans,s,t,Top,cnt,hd[MAXN],dep[MAXN],dp[MAXN],fa[MAXN],q[MAXN];
int rd(){
	int x=0,tp=1;char c=getchar();
	while(c<'0' || c>'9'){if(c=='-')tp=-1;c=getchar();}
	while(c>='0' && c<='9'){x=(x*10+c-'0');c=getchar();}
	return x*tp;
}
void adde(int x,int y){e[++cnt]=Edge(y,hd[x]);hd[x]=cnt;}
void dfs(int now,int f){
	dep[now]=dep[f]+1,fa[now]=f;
	dp[now]=(dep[now]%2)?1:-1;
	for(int i=hd[now];i;i=e[i].nex){
		if(e[i].to!=f){
			if(dep[e[i].to]){
				s=now,t=e[i].to;
				continue;
			}
			dfs(e[i].to,now);
			dp[now]+=dp[e[i].to];
		}
	}
}
void get_tree_ans(){
	if(dp[1]){printf("-1\n");exit(0);}
	for(int i=1;i<=n;i++)ans+=abs(dp[i]);
	printf("%d\n",ans);
}
void jihuan(){
	if(dp[1]%2){printf("-1\n");exit(0);}
	int tmp=-dp[1]/2;
	ans=abs(tmp);
	for(int i=s;i;i=fa[i])dp[i]+=tmp;
	for(int i=t;i;i=fa[i])dp[i]+=tmp;
	for(int i=1;i<=n;i++)ans+=abs(dp[i]);
	printf("%d\n",ans);
}
void ouhuan(){
	if(dp[1]){printf("-1\n");exit(0);}
	for(int i=t;i!=s;i=fa[i])q[++Top]=dp[i],dep[i]=0;
	sort(q+1,q+Top+1);
	int mid=q[(Top+1)/2];
	ans=abs(mid);
	for(int i=1;i<=n;i++)if(dep[i])ans+=abs(dp[i]);
	for(int i=1;i<=Top;i++)ans+=abs(q[i]-mid);
	printf("%d\n",ans);
}
int main(){
	// freopen("testdata.in","r",stdin);
	// freopen("1.out","w",stdout);
	int x,y;
	n=rd(),m=rd();
	for(int i=1;i<=m;i++){
		x=rd(),y=rd();
		adde(x,y),adde(y,x);
	}
	dfs(1,0);
	if(m==n-1){get_tree_ans();return 0;}
	if((dep[t]-dep[s])%2==0)jihuan();
	else ouhuan();
	// printf("%.2lf\n",(double)clock()/CLOCKS_PER_SEC);
	return 0;
}
```