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()
{
	string[] results;
	auto strs = readln.split;
	int n = to!int(strs[0]);
	int m = to!int(strs[1]);
	int a = to!int(strs[2]);
	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];
	}
	readln;
	a.writeln;
}