#include <stdio.h>

short Amida[101][1001];

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;
  }

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

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

  return 0;
}