Strange Graph
Time Limit: 10 Seconds Memory Limit: 32768 KB
Special Judge
Let us consider an undirected graph G = <V, E>. Let us denote by N(v) the set of vertices connected to vertex v (i.e. the set of neighbours of v). Recall that the number of vertices connected to v is called the degree of this vertex and is denoted by deg v.
We will call graph G strange if it is connected and for its every vertex v the following conditions are satisfied:
1. deg v 2 (i.e. there are at least two vertices connected to v)
2. If deg v = 2 then the two neighbours of v are not connected by an edge
3. If deg v > 2 then there is u N(v), such that the following is true:
(a) deg u = 2
(b) Any two different vertices w1, w2 N(v) \ {u} are connected,
i.e. ( w1, w2 )
E.
You are given some strange graph G. Find hamiltonian cycle in it, i.e. find such cycle that it goes through every vertex of G exactly once.
Input
Input consists of multiple test cases.For each case, the first line contains two integer numbers N and M -- the number of vertices and edges in G respectively (3



Output
For each test case, if there is no hamiltonian cycle in G, print in one line -1, otherwise output N numbers -- the sequence of vertices of G as they appear in the hamiltonian cycle found (note that the last vertex must be connected to the first one). If there are several solutions, output any one.Sample Input
4 4 1 2 2 3 3 4 4 1 9 12 1 2 2 3 3 1 1 4 2 5 3 6 4 7 5 8 6 9 7 8 8 9 9 7
Sample Output
1 2 3 4 -1Submit
Source: Northeastern Europe 2002, Northern Subregion