import std.stdio;
import std.array;
import std.conv;
import std.typecons;
import std.algorithm;
import std.container;
import std.bigint;

alias Tuple!(int, int, int) Couple;

void main()
{
	int[] results;
	while (true) {
		auto strs = readln.split;
		int n = to!int(strs[0]);
		int m = to!int(strs[1]);
		int a = to!int(strs[2]);
		if (n == m && m == a && a == 0) break;
		Couple[] t;
		foreach (i; 0..m) {
			strs = readln.split;
			int h = to!int(strs[0]);
			int p = to!int(strs[1]);
			int q = to!int(strs[2]);
			t ~= tuple(h, p, q);
		}
		sort!((Couple c1, Couple c2){return c1[0] > c2[0];})(t);
		int y = t[0][0]+1;
		foreach (i; 0..m) {
			int h = t[i][0];
			if (h > y) continue;
			y = h;
			if (a == t[i][1]) a = t[i][2];
			else if (a == t[i][2]) a = t[i][1];
		}
		results ~= a;
	}
	foreach (r; results)
		r.writeln;
}