/*
AizuOnline A2001
Amida
*/
#include <stdio.h>
// Select Below
//#include <stdlib.h>
//#include <string.h>
//#include <float.h>
//#include <math.h>
#include <limits.h>
//Global data section
int m,n,a;
struct amida {
  int h;
  int p;
  int q;} ami[1000];
//
int _read()
{
  int i;
  scanf("%d %d %d",&n,&m,&a);
  if(n==0 && m==0 && a==0)
    return(0);
  for(i=0;i<m;i++)
    {
      scanf("%d %d %d",&(ami[i].h),&(ami[i].p),&(ami[i].q));
    }
  return(-1);
}
int comp(void * x,void * y)
{
  return(((struct amida *)y)->h - ((struct amida *)x)->h);
}
show()
{
  int i;
  for(i=0;i<m;i++)
      printf("%d %d %d\n",ami[i].h,ami[i].p,ami[i].q);
}
main()
{
  int i,anext,mnext,hnext;

  
  while(_read())
    {
      qsort(ami,m,sizeof(struct amida),comp);
      //show();
      anext = a;
      hnext = INT_MAX;
      for(i=0;i<m;i++)
	{
	  //printf("hn:%d\n",hnext);
	  if(ami[i].h > hnext)
	    continue;
	  if(ami[i].p == anext)
	    {
	      anext = ami[i].q;
	      hnext  = ami[i].h - 1;
	    }
	  else if(ami[i].q == anext)
	    {
	      anext = ami[i].p;
	      hnext  = ami[i].h - 1;
	    } 
	}
      printf("%d\n",anext);
    }
  
return(0);
}