#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
using namespace std;
struct bar{int h,p,q; bool operator>(const bar &b)const{return h>b.h;}};
int main(){
	while(true){
		int n,m,a;
		vector<bar> vbars;
		cin>>n>>m>>a;
		if(n==0&&m==0&&a==0)break;

		for(int i = 0; i < m; ++i){
			bar b;
			cin>>b.h>>b.p>>b.q;
			vbars.push_back(b);
		}
		sort(vbars.begin(),vbars.end(),greater<bar>());
		for(unsigned int i = 0; i < vbars.size(); ++i){
			if( vbars[i].p == a ){
				a = vbars[i].q;
			}else if( vbars[i].q == a ){
				a = vbars[i].p;
			}
		}
		cout << a << endl;
	}
	return 0;
}

