#include <stdio.h>

int main() {
  int data[101][1001];
  int n,m,a;
  int h,p,q;
  int i,j;
  int hmax;
  int flag;

  hmax = 0;
  while(1){
    for(i = 0;i < 101; i++){
      for(j = 0; j < 1001;j++){
	data[i][j] = 0;
      }
    }
    scanf("%d %d %d",&n,&m,&a);  
    if(n == 0 && m == 0 && a == 0) break; 
    for(i = 0; i < m; i++){
      scanf("%d %d %d",&h,&p,&q); 
    if(p > q){
      p--;
      q++;
    }
    data[p][h] = 1;
    data[q][h] = -1;
    if(hmax < h)
      hmax = h;
    }
  
  h = hmax;
 flag = a;
  while(1){
    if(h == 0)
      break;
    flag = flag + data[flag][h];
    h--;
  }
  printf("%d\n",flag);
  }
  return 0;
}

 