#include <stdio.h>
#include <string.h>

int main(void)
{
	int n, m, a;
	int h[1001], p[1001], q[1001];
	int b[101];
	int i, j, k;
	int t;
	
	while (1){
		scanf("%d%d%d", &n, &m, &a);
		if ((n | m | a) == 0){
			break;
		}
		
		memset(p, 0, sizeof(p));
		memset(q, 0, sizeof(q));
		
		for (j = 0; j < m; j++){
			scanf("%d%d%d", &h[j], &p[j], &q[j]);
		}
		
		for (j = 0; j < m; j++){
			for (k = 0; k < m - 1; k++){
				if (h[k] > h[k + 1]){
					t = h[k];
					h[k] = h[k + 1];
					h[k + 1] = t;
					
					t = p[k];
					p[k] = p[k + 1];
					p[k + 1] = t;
					
					t = q[k];
					q[k] = q[k + 1];
					q[k + 1] = t;
				}
			}
		}
		
		for (j = 1; j <= n; j++){
			b[j] = j;
		}
		
		for (j = 0; j < m; j++){
//printf("<%d %d>", p[j], q[j]);
			t = b[p[j]];
			b[p[j]] = b[q[j]];
			b[q[j]] = t;
		}
		
		printf("%d\n", b[a]);
	}
	
	return (0);
}