// Aizu Vol-20 2001: Amida, the City of Miracle
// 2017.8.12 bal4u@uu

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

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

int cmp(T *p, T *q) { return q->h - p->h; }

int main()
{
	int n, m, a;

	while (1) {
		scanf("%d%d%d", &n, &m, &a); if (!n) break;
		for (p = t, e = p + m; p < e; p++) scanf("%d%d%d", &(p->h), &(p->p), &(p->q));
		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;
}