#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;
//P e[10000];
int es[105][1005] = { 0 };
int main() {
	while (true) {
		int n, m, a;
		cin >> n >> m >> a;
		if (n == 0) return 0;
		for (int i = 0; i < 105; i++)
			for (int j = 0; j < 1005; j++) es[i][j] = 0;
		for (int i = 0; i < m; i++) {
			int h, p, q;
			cin >> h >> p >> q;
			//e[h] = P(p, q);
			es[p][h] = q;
			es[q][h] = p;
		}
		int now = 1000;
		int ite = a;
		while (now >= 1) {
			if (es[ite][now] > 0) {
				ite = es[ite][now];
			}
			now--;
		}
		cout << ite << endl;
	}
	return 0;
}
