#include <stdio.h>

int solve(int n,  int m, int a){
  short line[101][1001] = {};
  int i, j,h, p, q;
  for(i = 0; i < m; i++){
    scanf("%d %d %d", &h, &p, &q);
    line[p][h] = q;
    line[q][h] = p;
  }
  
  i = 1000;
  j = 0;
  while(j < m){
    if(line[a][i] != 0){
      a = line[a][i];
      j++;
    }
    i--;
    if(i <= 0) break;
  }

  return a;
}

int main(void){
  int n, m, a;

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

  return 0;
}
