#include <stdio.h>
#include<limits.h>

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

  hmax = INT_MIN;

  for(i = 0;i < 101; i++){
    for(j = 0; j < 101;j++){
      data[i][j] = 0;
    }
  }
  scanf("%d %d %d",&n,&m,&a);
  
  while(1){
    scanf("%d %d %d",&h,&p,&q);
    if(h == 0 && p == 0 && q == 0) break;
    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;
}

 