#include <stdio.h>

int main(void){
  int i,j;
  int n,m,a;
  int h,p,q;
  int max_h;
  int amida[1004][104];

  while(1){
    scanf("%d%d%d",&n,&m,&a);
    if(n==0 && m==0 && a==0) break;

    for(i=0;i<1004;i++){
      for(j=0;j<n;j++){
	amida[i][j] = 0;
      }
    }

    max_h = -1;
    for(i=0;i<m;i++){
      scanf("%d%d%d",&h,&p,&q);
      amida[h-1][p-1] = 1;
      amida[h-1][q-1] = 2;
      if(max_h < h){
	max_h = h;
      }
    }

    i = max_h - 1;
    j = a - 1;
    for(; i != -1; i--){
      if(amida[i][j] == 1){
	j++;
      }
      else if(amida[i][j] == 2){
	j--;
      }
    }
    printf("%d\n",j+1);
  }


  return 0;
}