#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
	int n, m, a;
	while(cin >> n >> m >> a, n){
		vector< pair<int, pair<int, int> > > vp(m);
		for(int i=0;i<m;i++){
			cin >> vp[i].first >> vp[i].second.first >> vp[i].second.second;
		}
		sort(vp.rbegin(), vp.rend());
		for(int i=0;i<m;i++){
			if(vp[i].second.first == a){
				a = vp[i].second.second;
			} else if(vp[i].second.second == a){
				a = vp[i].second.first;
			}
		}
		cout << a << endl;
	}
}