#include <stdio.h>
#include <string.h>

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

int main() {
    int n, m, a, i, h;
    HL hl[1001];

    while (scanf("%d %d %d", &n, &m, &a) != EOF) {
        if (!n && !m && !a) { break; }
        memset(hl, 0, sizeof(hl));

        for (i = 0; i < m; i++) {
            scanf("%d %d %d", &hl[i].h, &hl[i].p, &hl[i].q);
        }

        int ans = a;

        for (h = 1000; h > 0; h--) {
            for (i = 0; i < m; i++) {
                if (hl[i].h != h) { continue; }
                if (hl[i].p == ans) {
                    ans = hl[i].q;
                    break;
                } else if (hl[i].q == ans) {
                    ans = hl[i].p;
                    break;
                }
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}
