//
//  main.c
//  Amida, the City of Miracle
//
//  Created by x15071xx on 2016/06/09.
//  Copyright ?? 2016??´ AIT. All rights reserved.
//

#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    
    
    
    while (1) {
        
        int n,m,a,i,j,h,p,q;
        int field[1002][200] ={0};
        scanf("%d %d %d",&n,&m,&a);
        
        if (n==0 && m==0 && a==0) {
            break;
        }
        
        for (i=0; i<n; i++) {
            field[0][i*2] = i+1;
            field[1001][i*2] = i+1;
            //??????
            for (j=1; j < 1001; j++) {
                field[j][i*2] = 1;
            }
        }
        
        for (i=0; i<m; i++) {
            scanf("%d %d %d",&h,&p,&q);
            
            field[1001-h][p+q-2] = 1;
            
        }
        
        //?????????
        int y = a*2-2;
        for (i=0; i < 1001; i++) {
            
            if (field[i][y+1] == 1) {
                y+=2;
                continue;
            }
            if (field[i][y-1] == 1) {
                y-=2;
                continue;
            }
        }
        
        
        printf("%d\n",field[1001][y]);
        

    }
    return 0;
}