#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n, m, a, h, p, q;
	while (cin >> n >> m >> a, n || m || a) {
		vector< vector<int> > amida(n + 1, vector<int>(1001, -1));
		int retu = a, takasa = 1000;
		for (int i = 0; i < m; i++) {
			cin >> h >> p >> q;
			amida[p][h] = q;
			amida[q][h] = p;
		}
		for (; takasa > 0; takasa--) {
			if (amida[retu][takasa] != -1) {
				retu = amida[retu][takasa];
			}
		}
		cout << retu << endl;
	}
	return 0;
}