#include <bits/stdc++.h>
using namespace std;

typedef pair< int, pair<int, int>> PIPII;

int main() {
	int N, M, A;
	while( cin >> N >> M >> A, N || M || A ) {
		vector<int>D( N );
		iota( D.begin(), D.end(), 1 );
		priority_queue<PIPII, vector<PIPII>>que;
		for( size_t i = 0; i < M; i++ ) {
			int H, P, Q;
			cin >> H >> P >> Q;
			P--; Q--;
			que.push( make_pair( H, make_pair( P, Q ) ) );
		}
		while( que.size() ) {
			PIPII now = que.top(); que.pop();
			swap( D[now.second.first], D[now.second.second] );
		}
		for( size_t i = 0; i < N; i++ ) {
			if( D[i] == A ) {
				cout << i + 1 << endl;
			}
		}
	}
}