#include <stdio.h>
#include <stdbool.h>
#include <math.h>
#include <limits.h>
#include <stdlib.h>
#include <string.h>

#define REP(i, n) for((i) = 0; (i) < (n); (i)++)
#define READ1(n1) scanf("%d", &(n1))
#define READ2(n1, n2) scanf("%d%d", &(n1), &(n2))
#define READ3(n1, n2, n3) scanf("%d%d%d", &(n1), &(n2), &(n3))
#define P1(n1) printf("%d\n", (n1))
#define P2(n1, n2) printf("%d, %d\n", (n1), (n2))
#define P3(n1, n2, n3) printf("%d, %d, %d\n", (n1), (n2), (n3))
#define CLEAR(p) memset((p), 0, sizeof((p)))
#define MAX_COLUMN 101
#define MAX_ROW 1001

char bars[MAX_COLUMN][MAX_ROW];

main()
{
	while(1) {
		int i;
		int vbar_num, hbar_num, x, y;

		CLEAR(bars);

		READ3(vbar_num, hbar_num, x);

		if(vbar_num == 0) break;

		REP(i, hbar_num) {
			int height, left, right;

			READ3(height, left, right);

			bars[left][height] = 1;
		}

		for(y = 1000; y > 0; y--) {
			if(bars[x][y]) {
				x++;
			} else if(bars[x-1][y]) {
				x--;
			}
		}

		P1(x);
	}
	return 0;
}