import std.stdio,std.conv, std.algorithm, std.container,std.array,std.range,std.string,std.typecons;
const dx = [1,0,-1,0];
const dy = [0,1,0,-1];
int sum(int n){return n * (n + 1)/ 2;}
void read(T...)(auto ref T args){ 
	auto line = readln().split(); 
	if (line.length < args.length) return;
	foreach(i,ref arg; args) arg = line[i].to!(typeof(arg));
}
struct line{int y,p,q;}
void main(){	
	int v,h,nowx;
	while(read(v,h,nowx),v|h|nowx){
		line[] lines;
		for(;h>0;h--){
			int y,p,q;
			read(y,p,q);
			lines ~= line(y,p,q);
		}
		lines.sort!("a.y > b.y");
		foreach(ln;lines){
			if(nowx == ln.p) nowx = ln.q;
			else if(nowx == ln.q) nowx = ln.p;
		}
		nowx.writeln;
	}
}