#include<stdio.h>
#include<stdlib.h>

typedef struct {
	int height;
	int num1, num2;
} Rail;

#define MAX_M 1000

int n, m, a;
Rail rail[MAX_M];

int int_sort( const void *a, const void *b )
{
	Rail rail_a, rail_b;
	int tmp_a, tmp_b;
	rail_a = *(Rail *)a;
	rail_b = *(Rail *)b;
	tmp_a = rail_a.height;
	tmp_b = rail_b.height;
	if ( tmp_a > tmp_b ) {
		return -1;
	}
	if ( tmp_a < tmp_b ) {
		return 1;
	}
	return 0;
}

int main(void)
{
	int i;
	
	while(1) {
		
		scanf( "%d %d %d", &n, &m, &a );
		
		if ( n == 0 ) break;
		
		for( i=0; i<m; i++ ) {
			scanf( "%d %d %d", &rail[i].height, &rail[i].num1, &rail[i].num2 );
		}
	
		qsort( (void *)rail, m, sizeof( rail[0] ), int_sort );
		
		for( i=0; i<m; i++ ) {
			if ( a == rail[i].num1 )
				a = rail[i].num2;
			else
				if ( a == rail[i].num2 )
					a = rail[i].num1;
		}
		
		printf( "%d\n", a );
	}
	return 0;
}