#include <bits/stdc++.h>
using namespace std;

int main()
{
	int n, m, a;
	while(cin >> n >> m >> a, n|m|a)
	{
		map<int, map<int, int> > amida;
		for(int i=0; i<m; i++)
		{
			int h, p, q;
			cin >> h >> p >> q;
			amida[h][p] = q;
			amida[h][q] = p;
		}
		int pos = a;
		for(map<int, map<int, int> >::reverse_iterator i=amida.rbegin(); i!=amida.rend(); i++)
		{
			map<int, int>::iterator j = i->second.find(pos);
			if(j!=i->second.end())
			{
				pos = j->second;
			}
		}
		cout << pos << endl;
	}
	
	return 0;
}