#include <stdio.h>
#include <stdlib.h>
#define N_MAX 100
#define M_MAX 1000

typedef struct hbar { int h, p, q; } hbar;

int comp_hbars(const void* a, const void* b) { return (*(hbar*)b).h - (*(hbar*)a).h; }

int main(void)
{
    int i, m, a;
    hbar hbars[M_MAX];

    while(scanf("%*d %d %d", &m, &a), m + a)
    {
        for(i = 0; i < m; i++)
            scanf("%d %d %d", &hbars[i].h, &hbars[i].p, &hbars[i].q);

        qsort(hbars, m, sizeof(hbar), comp_hbars);

        for(i = 0; i < m; i++)
            if(hbars[i].p == a) a = hbars[i].q;
            else if(hbars[i].q == a) a = hbars[i].p;

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

    return 0;
}