Doug the Friendly Scavenger --------------------------- Doug lives in Graphland. Graphland consists of a collection of nodes. Pairs of nodes are connected by edges, along which Doug may travel (in either direction). If there is an edge between two nodes, those nodes are called adjacent. There are n nodes and m edges. The nodes are numbered 1 to n. Doug starts out at node number 1. Doug is in a scavenger hunt. He wants to visit every node in Graphland to look for items. He decides on the following strategy: (1) Try to go to an adjacent node that has not already been visited. (2) If there is more than one such node, pick the one with the lowest number. (3) If there is no such node, backtrack along the path travelled so far until there is such an adjacent unvisited node. Doug stops when there are no unvisited nodes adjacent to any visited node. Your job is to output the list of nodes in the order that Doug visits them for the first time. Input ----- The input will have several instances. Each instance will begin with a line containing integers n and m (1 <= n <= 1000 and 0 <= m <= 1000000). Then there will be m lines, each containing two positive integers i and j (1 <= i,j <= n). Each such line indicates that there is an edge between node number i and node number j. The end of the input will be indicated by a line with n=m=0. Output ------ For each instance, output, on a single line a list of nodes in the order they are visited for the first time. Put a single space between each pair of node names in the list. Sample Input ------------ 4 3 1 2 2 4 1 4 5 5 1 3 2 3 1 5 1 4 5 4 0 0 Sample Output ------------- 1 2 4 1 3 2 4 5