#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)

int main(){
	int n,m,a;
	while(cin>>n>>m>>a&&(n||m||a)){
		vector<pair<int,pii>> vp;
		rep(i,m){
			int h,p,q;
			cin>>h>>p>>q;
			vp.pb(make_pair(h,pii(p,q)));
		}
	
		sort(vp.rbegin(),vp.rend());
	
		for(auto e:vp){
			int l=e.second.first;
			int r=e.second.second;
		
			if(l==a)a = r;
			else if(r==a)a=l;
		}
		cout<<a<<endl;
	}
}