Problem: Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.

Vova has a non-directed graph consisting of n vertices and m edges without loops and multiple edges. Let's define the operation of contraction two vertices a and b that are not connected by an edge. As a result of this operation vertices a and b are deleted and instead of them a new vertex x is added into the graph, and also edges are drawn from it to all vertices that were connected with a or with b (specifically, if the vertex was connected with both a and b, then also exactly one edge is added from x to it). Thus, as a result of contraction again a non-directed graph is formed, it contains no loops nor multiple edges, and it contains (n - 1) vertices.

Vova must perform the contraction an arbitrary number of times to transform the given graph into a chain of the maximum length. A chain of length k (k ≥ 0) is a connected graph whose vertices can be numbered with integers from 1 to k + 1 so that the edges of the graph connect all pairs of vertices (i, i + 1) (1 ≤ i ≤ k) and only them. Specifically, the graph that consists of one vertex is a chain of length 0. The vertices that are formed as a result of the contraction are allowed to be used in the following operations of contraction.

<image> The picture illustrates the contraction of two vertices marked by red.

Help Vova cope with his girlfriend's task. Find the maximum length of the chain that can be obtained from the resulting graph or else determine that it is impossible to obtain the chain.

Input

The first line contains two integers n, m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the original graph.

Next m lines contain the descriptions of edges in the format ai, bi (1 ≤ ai, bi ≤ n, ai ≠ bi), which means that there is an edge between vertices ai and bi. It is guaranteed that there is at most one edge between each pair of vertexes.

Output

If it is impossible to obtain a chain from the given graph, print  - 1. Otherwise, print the maximum possible number of edges in the resulting chain.

Examples

Input

5 4
1 2
2 3
3 4
3 5


Output

3


Input

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


Output

-1


Input

4 2
1 3
2 4


Output

2

Note

In the first sample test you can contract vertices 4 and 5 and obtain a chain of length 3.

In the second sample test it is initially impossible to contract any pair of vertexes, so it is impossible to achieve the desired result.

In the third sample test you can contract vertices 1 and 2 and obtain a chain of length 2.

Solution (in JAVA):

Solution:
import java.io.*;
import java.util.*;
public class PlayGraph{
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskE solver = new TaskE();
        solver.solve(1, in, out);
        out.flush();out.close();
    }
        static class TaskE {
            final int max = 1010;
            int n , m;
            int val[] = new int[max];
            ArrayDeque<Integer> ad = new ArrayDeque<>();
            int R[] = new int[max] , pa[] = new int[max];
            ArrayList<Integer> al[] = new ArrayList[max];
            int find(int u){
                if(pa[u] == u)return u;
                return pa[u] = find(pa[u]);
            }
            void merge(int u , int v){
                u = find(u) ; v = find(v);
                if(R[u] == R[v]){
                    R[u]++;
                }
                if(R[u] < R[v]){
                    u ^= v; v ^= u; u ^= v;
                }
                pa[v] = u;
            }
           public void solve(int testNumber, InputReader in, PrintWriter out) {
            n = in.nextInt(); m = in.nextInt();
            for(int i = 1; i <= n; i++)pa[i] = i;
            make(n , m , in);
            for(int i = 0; i < max; i++){
                al[i] = new ArrayList<>();
            }
            for(int i = 1; i <= n; i++){
                find(i);
                al[pa[i]].add(i);
            }
            int ans = 0;
            for(int x = 1; x <= n; x++){
                if(al[x].size() <= 1)continue;
                int l = al[x].size();
                int oans = -1;
                o : for(int ii = 0; ii < l; ii++){
                    Arrays.fill(val , 0);
                    ad.clear();
                    int i = al[x].get(ii);
                    ad.add(i); val[i] = 1; int pans = -1;
                    while(!ad.isEmpty()){
                        int u = ad.pollFirst();
                        for(int v : ja[u]){
                            if(val[v] == 0){
                                ad.addLast(v); val[v] = val[u] + 1;
                                pans = Math.max(pans , val[v]);
                            }else if(val[v] == val[u]){
                                continue o;
                            }
                        }
                    }
                    oans = Math.max(oans , pans - 1);
                }
                if(oans == -1){
                    ans = -1;break;
                }
                ans += oans;
            }
            out.println(ans);
          }
            int ja[][], from[],to[],c[];
            void make(int n,int m,InputReader in){
             ja=new int[n+1][];from=new int[m];to=new int[m];c=new int[n+1];
             for(int i=0;i<m;i++){
              int u=in.nextInt(),v=in.nextInt();
              c[u]++;c[v]++;from[i]=u;to[i]=v; merge(u , v);
             }
             for(int i=1;i<=n;i++){
              ja[i]=new int[c[i]];c[i]=0;
             }
             for(int i=0;i<m;i++){
              ja[from[i]][c[from[i]]++]= to[i];
              ja[to[i]][c[to[i]]++]= from[i];
             }
            }
//        int[] radixSort(int[] f){ return radixSort(f, f.length); }
//    int[] radixSort(int[] f, int n)
//    {
//        int[] to = new int[n];
//        {
//            int[] b = new int[65537];
//            for(int i = 0;i < n;i++)b[1+(f[i]&0xffff)]++;
//            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//            for(int i = 0;i < n;i++)to[b[f[i]&0xffff]++] = f[i];
//            int[] d = f; f = to;to = d;
//        }
//        {
//            int[] b = new int[65537];
//            for(int i = 0;i < n;i++)b[1+(f[i]>>>16)]++;
//            for(int i = 1;i <= 65536;i++)b[i]+=b[i-1];
//            for(int i = 0;i < n;i++)to[b[f[i]>>>16]++] = f[i];
//            int[] d = f; f = to;to = d;
//        }
//        return f;
//    }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;
        public InputReader(InputStream stream) {
            br = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}