#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
	int n, m, a;
	int line[1024][128] = {0};
	
	while (1){
		cin >> n >> m >> a;
		
		if (!n && !m && !a){
			break;
		}
		
		for (int i = 0; i < m; i++){
			int h, p, q;
			cin >> h >> p >> q;
			
			line[h][p] = q;
			line[h][q] = p;
		}
		
		for (int i = m; i > 0; i--){
			if (line[i][a] != 0){
				a = line[i][a];
			}
		}
		
		cout << a << endl;
	}
	
	return 0;
}