package main import ( "fmt" ) func main() { n := 0 head := 0 fmt.Scan(&n) fmt.Scan(&head) ans := []int{head} for i := 0; i < n-1; i++ { x, y := 0, 0 fmt.Scan(&x, &y) for j := 0; j < len(ans); j++ { if ans[j] == y { ans = append(append(append([]int{}, ans[:j+1]...), x), ans[j+1:]...) break } } } del := 0 fmt.Scan(&del) for i := 0; i < len(ans); i++ { if ans[i] == del { continue } fmt.Print(ans[i], " ") } }