import java.io.*; public class ICPC_B { public static void main(String args[]) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); while (solve(br)) ; } private static boolean solve(BufferedReader in) throws IOException { int[][] cubes = new int[100][101]; int numberOfCubes = Integer.parseInt(in.readLine()); if (numberOfCubes <= 0) return false; for (int index = 0; index < numberOfCubes; index++) { cubes[index][0] = 1; cubes[index][1] = index + 1; } for (;;) { // 指示を読む String line = in.readLine(); if (line.equals("0 0")) break; int from = Integer.parseInt(line.substring(0, line.indexOf(" "))), to = Integer.parseInt(line.substring(line.indexOf(" ") + 1)); if (to == from) continue; int fromPile, fromIndex, toPile, toIndex, tmp; tmp = searchCube(cubes, from); fromPile = tmp / 1000; fromIndex = tmp % 1000; tmp = searchCube(cubes, to); toPile = tmp / 1000; toIndex = tmp % 1000; if (fromPile == toPile && fromIndex > toIndex) continue; else if (to == 0 && fromIndex == 1) continue; while (cubes[fromPile][0] > fromIndex) movePile(cubes, fromPile, cubes[fromPile][0], getEmptyPile(cubes)); if (to == 0) toPile = getEmptyPile(cubes); movePile(cubes, fromPile, fromIndex, toPile); } // 個数の順にソート for (int i = 0; i < cubes.length - 1; i++) { int min = i; for (int j = i + 1; j < cubes.length; j++) { if (cubes[j][0] < cubes[min][0]) min = j; } int swap = cubes[i][0]; cubes[i][0] = cubes[min][0]; cubes[min][0] = swap; } // 出力 int pile = 0; for (; pile < cubes.length && cubes[pile][0] == 0; pile++) ; for (; pile < cubes.length; pile++) System.out.println(cubes[pile][0]); System.out.println("end"); return true; } // solve private static int searchCube(int[][] cubes, int id) { if (id == 0) return 0; for (int pile = 0; pile < cubes.length; pile++) { for (int index = 1; index <= cubes[pile][0]; index++) { if (cubes[pile][index] == id) return pile * 1000 + index; } } throw new RuntimeException("Internal error..."); } private static int getEmptyPile(int[][] cubes) { for (int pile = 0; pile < cubes.length; pile++) { if (cubes[pile][0] == 0) return pile; } throw new RuntimeException("Internal error..."); } private static void movePile(int[][] cubes, int fromPile, int fromIndex, int toPile) { if (fromIndex > cubes[fromPile][0]) return; int length = cubes[fromPile][0] - fromIndex + 1; System.arraycopy(cubes[fromPile], fromIndex, cubes[toPile], cubes[toPile][0] + 1, length); cubes[fromPile][0] -= length; cubes[toPile][0] += length; } } // ICPC_B