Problem: Mr. Endo wanted to write the code that performs breadth-first search (BFS), which is a search algorithm to explore all vertices on an undirected graph. An example of pseudo code of BFS is as follows:


1: $current \leftarrow \{start\_vertex\}$
2: $visited \leftarrow current$
3: while $visited \ne $ the set of all the vertices
4:   $found \leftarrow \{\}$
5:   for $v$ in $current$
6:     for each $u$ adjacent to $v$
7:       $found \leftarrow found \cup\{u\}$
8:   $current \leftarrow found \setminus visited$
9:   $visited \leftarrow visited \cup found$


However, Mr. Endo apparently forgot to manage visited vertices in his code. More precisely, he wrote the following code:


1: $current \leftarrow \{start\_vertex\}$
2: while $current \ne $ the set of all the vertices
3:   $found \leftarrow \{\}$
4:   for $v$ in $current$
5:     for each $u$ adjacent to $v$
6:       $found \leftarrow found \cup \{u\}$
7:   $current \leftarrow found$


You may notice that for some graphs, Mr. Endo's program will not stop because it keeps running infinitely. Notice that it does not necessarily mean the program cannot explore all the vertices within finite steps. See example 2 below for more details.Your task here is to make a program that determines whether Mr. Endo's program will stop within finite steps for a given graph in order to point out the bug to him. Also, calculate the minimum number of loop iterations required for the program to stop if it is finite.



Input

The input consists of a single test case formatted as follows.


$N$ $M$
$U_1$ $V_1$
...
$U_M$ $V_M$


The first line consists of two integers $N$ ($2 \leq N \leq 100,000$) and $M$ ($1 \leq M \leq 100,000$), where $N$ is the number of vertices and $M$ is the number of edges in a given undirected graph, respectively. The $i$-th line of the following $M$ lines consists of two integers $U_i$ and $V_i$ ($1 \leq U_i, V_i \leq N$), which means the vertices $U_i$ and $V_i$ are adjacent in the given graph. The vertex 1 is the start vertex, i.e. $start\\_vertex$ in the pseudo codes. You can assume that the given graph also meets the following conditions.

* The graph has no self-loop, i.e., $U_i \ne V_i$ for all $1 \leq i \leq M$.
* The graph has no multi-edge, i.e., $\\{Ui,Vi\\} \ne \\{U_j,V_j\\}$ for all $1 \leq i < j \leq M$.
* The graph is connected, i.e., there is at least one path from $U$ to $V$ (and vice versa) for all vertices $1 \leq U, V \leq N$

Output

If Mr. Endo's wrong BFS code cannot stop within finite steps for the given input graph, print -1 in a line. Otherwise, print the minimum number of loop iterations required to stop.

Examples

Input

3 3
1 2
1 3
2 3


Output

2


Input

4 3
1 2
2 3
3 4


Output

-1


Input

4 4
1 2
2 3
3 4
4 1


Output

-1


Input

8 9
2 1
3 5
1 6
2 5
3 1
8 4
2 7
7 1
7 4


Output

3

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> PP;
int n,m;
int col[100005];
vector<int> G[100005];
int dist[100005];
vector<PP> vec;
int dist2[100005];

bool check(int vt){
	memset(dist2,-1,sizeof(dist2));
	int now=0;
	queue<int> que;
	int cnt=0;
	for(int i=0;i<=vt;i++){
		queue<int> tmp;
		while(que.size()){
			int v=que.front();
			cnt++;
			que.pop();
			for(int i=0;i<G[v].size();i++){
				if(dist2[G[v][i]]==-1){
					dist2[G[v][i]]=dist[v]+1;
					tmp.push(G[v][i]);
				}
			}
		}
		while(tmp.size()){
			int v=tmp.front();
			tmp.pop();
			que.push(v);
		}
		while(now<vec.size() && vec[now].first<=i){
			P p=vec[now].second;
			if(dist2[p.first]==-1){
				que.push(p.first);
				dist2[p.first]=i;
			}
			if(dist2[p.second]==-1){
				que.push(p.second);
				dist2[p.second]=i;
			}
			now++;
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		if(dist2[i]==-1 && (dist[i]%2!=vt%2 || dist[i]>vt))return false;
	}
	return true;
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		u--;
		v--;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	memset(dist,-1,sizeof(dist));
	dist[0]=0;
	queue<int> que;
	que.push(0);
	while(que.size()){
		int v=que.front();
		que.pop();
		for(int i=0;i<G[v].size();i++){
			if(dist[G[v][i]]==-1){
				dist[G[v][i]]=dist[v]+1;
				que.push(G[v][i]);
			}
		}
	}
	bool flag=false;
	for(int i=0;i<n;i++){
		for(int j=0;j<G[i].size();j++){
			if((dist[i]+dist[G[i][j]])%2==0){
				flag=true;
				vec.push_back(PP(max(dist[i],dist[G[i][j]]),P(i,G[i][j])));
			}
		}
	}
	if(!flag){
		printf("-1\n");
		return 0;
	}
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end());
	int l=0,r=n*3;
	while(l+1<r){
		int mid=(l+r)/2;
		if(check(mid*2))r=mid;
		else l=mid;
	}
	int nl=-1,nr=n*3;
	while(nl+1<nr){
		int mid=(nl+nr)/2;
		if(check(mid*2+1))nr=mid;
		else nl=mid;
	}
	printf("%d\n",min(r*2,nr*2+1));
	return 0;
}