// AOJ 2001: Amida, the City of Miracle
// 2017.8.12 bal4u@uu
// 2017.11.7 retry

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

typedef struct { int h, p, q; } T;
T t[1003];

char buf[30], *bp;
int getint()
{
	int n = 0;
	while (*bp >= '0') n = (n<<3) + (n<<1) + (*bp++ & 0xf);
	return n;
}

int cmp(T *a, T *b) { return b->h - a->h; }

int main()
{
	int n, m, a;
	T *p, *e;

	while (fgets(bp=buf, 30, stdin) && *buf != '0') {
		n = getint(), bp++, m = getint(), bp++, a = getint();
		for (p = t, e = p + m; p < e; p++) {
			fgets(bp=buf, 30, stdin);
			p->h = getint(), bp++, p->p = getint(), bp++, p->q = getint();
		}
		qsort(t, m, sizeof(T), cmp);
		for (p = t, e = p + m; p < e; p++) {
			if      (p->p == a) a = p->q;
			else if (p->q == a) a = p->p;
		}
		printf("%d\n", a);
	}
	return 0;
}