#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;

int main() {
	int a, b, c;
	while (cin >> a >> b >> c, a | b | c) {
		int d[101]{};
		for (int e = 1; e < a+1; e++)d[e] = e;
		multimap<int, vector<int>>f;
		for (int g = 0; g < b; g++) {
			int h; vector<int>i(2);
			cin >> h >> i[0] >> i[1];
			f.insert(pair<int, vector<int>>(h, i));
		}
		for (auto k = f.begin(); k != f.end(); k++) {
			int l = d[(*k).second[0]];
			d[(*k).second[0]] = d[(*k).second[1]];
			d[(*k).second[1]] = l;
		}
		cout << d[c] << endl;
	}
}