#include <iostream>
#include <string.h>
using namespace std;
int main(){
	while( 1 ){
		int n, m, a;
		int lottery[1001][101];
		memset( lottery, 0, sizeof(lottery) );
		cin >> n >> m >> a;
		if( n == 0 ) break;
		while( m-- > 0 ){
			int h, p, q;
			cin >> h >> p >> q;
			lottery[1000-h][p] = q;
			lottery[1000-h][q] = p;
		}
		for( int i = 1; i <= 1000; i++ ){
			for( int j = 1; j <= 100; j++ ){
				if( lottery[i][j] && a == j ){
					a = lottery[i][j];
					break;
				}
			}
		}
		cout << a << endl;
	}
}