const readline = require('readline')
const rl = readline.createInterface({
input:process.stdin,
output:process.stdout
})
let inp = []
rl.on('line',(line)=>{
inp = line.split(' ')
})
rl.on('close',()=>{
for(i in inp) {
inp[i] = parseInt(inp[i])
}
let res = []
res.push(inp[1])
while(res.length<inp[0]) {
res.push('')
}
let del = inp.pop()
inp.splice(0,2)
for(let i=0; i<inp.length;i+=2) {
let index = res.indexOf(inp[i+1])
res.splice(index+1,0,inp[i])
}
let dindex = res.indexOf(del)
res.splice(dindex,1)
console.log(res.join(' ').trim())
})