#include <stdio.h>



#define HEIGHT_MAX 1000
#define N_MAX 100


int main(int argc, char **argv)
{
	char inputline[14];
	int n, m, line_a;
	int height, line_p, line_q;
	int i, j;
	int map[N_MAX][HEIGHT_MAX];
	
	
	while( 1 ){
	for( i = 0; i < 100; i++){
		for( j = 0; j < 1000; j++)
			map[i][j] = i;
	}
	
	fgets( inputline, sizeof( inputline ), stdin );
	sscanf( inputline, "%d%d%d", &n, &m, &line_a );
	if( n == 0 && m == 0 && line_a == 0 )
		break;
	if( n > N_MAX || n < 2 ||
		m > 1000 || m < 0 ||
		1 > line_a || line_a > n ){
			return -1;
	}
	line_a--;
	
	for(i = 0; i < m; i++){
		fgets( inputline, sizeof( inputline ), stdin );
		sscanf( inputline, "%d%d%d", &height, &line_p, &line_q );
		if( height < 1 || height > 1000 ||
			line_p < 1 || line_p >= line_q || line_q > n ){
				return -1;
			}
		line_p--;
		line_q--;
		height--;
		if( map[line_p][height] != line_p || map[line_q][height] != line_q )
			return 1;
		else{
			map[line_p][height] = line_q;
			map[line_q][height] = line_p;
		}
	}
	
	for(i = 0; i < HEIGHT_MAX; i++ )
		line_a = map[line_a][i];
	
	
	line_a++;
	printf("%d\n", line_a);
	
	}
		
	return 0;
	
}