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

int
main (void)
{
  int n, m, a, i;
  int data[1000][100];
  while (1)
    {
      scanf ("%d%d%d", &n, &m, &a);
      if ((n | m | a) == 0)
	exit (0);
      memset (data, 0, 1000 * 100 * sizeof (int));
      while (1)
	{
	  int h, from, to;
	  scanf ("%d%d%d", &h, &from, &to);
	  if ((h | from | to) == 0)
	    exit (0);
	  data[h - 1][from - 1] = to;
	  data[h - 1][to - 1] = from;
	  if (m-- <= 1)
	    break;
	}
      for (i = 1000; i > 0; i--)
	{
	  if (data[i - 1][a - 1] == 0)
	    continue;
	  a = data[i - 1][a - 1];
	}
      printf ("%d\n", a);
    }
}