Bob the Friendly Scavenger -------------------------- Bob lives in Graphland. Graphland consists of a collection of nodes. Pairs of nodes are connected by edges, along which Bob 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. Bob starts out at node number 1. Bob 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 a node that has not already been visited whose path from 1 is a shortest among the unvisited nodes. (2) If there is more than one such node, visit them in the order of the path from 1 to the node, ordered lexicographically. Bob 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 Bob 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 ------------ 7 8 1 2 3 1 2 3 3 4 4 5 5 3 6 2 2 7 0 0 Sample Output ------------- 1 2 3 6 7 4 5