#include <stdio.h>

int main(void) {
	int i, j;
	int n, m, a;

	while (scanf("%d %d %d", &n, &m, &a), n) {
		int h[1000], p[1000], q[1000];
		int cur_h;

		for (i = 0; i < m; i++)
			scanf("%d %d %d", h + i, p + i, q + i);

		for (cur_h = 1000; cur_h >= 0; cur_h--)
			for (j = 0; j < m; j++)
				if (h[j] == cur_h)
					if (p[j] == a) {
						a = q[j];
						break;
					} else if (q[j] == a) {
						a = p[j];
						break;
					}

		printf("%d\n", a);
	}

	return 0;
}