#include <stdio.h>
#include <stdlib.h>

int n,m,a;
typedef struct{
	int h;
	int p;
	int q;
} wire;
wire lines[1001];

int comp(const void *c1,const void *c2){
	wire *w1=(wire*)c1;
	wire *w2=(wire*)c2;
	return w2->h - w1->h;
}

void solve(){
	int i,h,p,q;
	for(i=1;i<=1000;i++){
		lines[i].h=0;
		lines[i].p=0;
		lines[i].q=0;
	}
	for(i=0;i<m;i++){
		scanf("%d %d %d",&h,&p,&q);
		lines[i].h=h;
		lines[i].p=p;
		lines[i].q=q;
	}
	qsort(lines,m,sizeof(wire),comp);

	h=lines[0].h;
	i=0;
	while(h){
		for(;lines[i].h==h;i++){
			if(lines[i].p==a){
				a=lines[i].q;
			}else if(lines[i].q==a){
				a=lines[i].p;
			}
		}
		h--;
	}
	printf("%d\n",a);
	return;
}


int main(void){
	while(scanf("%d %d %d",&n,&m,&a),n|m|a){
		solve();
	}
	return 0;
}