#include <stdio.h>
#include <stdlib.h>

#define N 100
#define M 1000
#define INT(X) \
  ( *( (const int *)(X) ) )

int comparator (
  const void  * a,
  const void  * b
  )
{
  return ( INT( b ) - INT( a ) );
}

/** Application main entry point. */
int main (
  int     argc,
  char  * argv[ ]
  )
{
  int i;

  for ( ; ; )
  {
    struct tagD
    {
      int h;
      int p;
      int q;
    } d[ M ];
    int n, m, a;

    scanf ( "%d%d%d", &n, &m, &a );
    if ( !( n | m | a ) ) break ;

    for ( i = 0; i < m; ++i )
    {
      scanf ( "%d%d%d", &d[ i ].h, &d[ i ].p, &d[ i ].q );
    }
    qsort ( d, m, sizeof ( struct tagD ), comparator );

    for ( i = 0; i < m; ++i )
    {
      if ( d[ i ].p == a )
      {
        a = d[ i ].q;
      }
      else if ( d[ i ].q == a )
      {
        a = d[ i ].p;
      }
    }

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

  return ( 0 );
}