#include <stdio.h>

short Amida[101][1001];

void debugPrint(int N,int M) {
  int n,m;
  for(m=M;m>=0;m--) {
    for(n=1;n<=N;n++) {
      printf("%d ", (Amida[n][m])? Amida[n][m]:0);
    }
    printf("\n");
  }
}

int main() {
  int N,M,m,A,a;
  scanf("%d %d %d\n",&N,&M,&A);

  for(m=0;m<M;m++) {
    int H,P,Q;
    scanf("%d %d %d",&H,&P,&Q);
    Amida[P][H] = Q;
    Amida[Q][H] = P;
  }

  //  debugPrint(N,M);

  a = A;
  for(m=M;m>0;m--) {
    if (Amida[a][m]) {
      a = Amida[a][m];
    }
  }

  printf("%d\n",a);

  return 0;
}