#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
int edge[111][1111];
int main(void){
  while(1){

    int n,m,a;
    cin >> n >> m >> a;
    if(!n && !m && !a) break;
    a--;

    for(int i = 0; i < n; i++){
      fill(edge[i],edge[i] + 1111,i);
    }

    for(int i = 0; i < m; i++){
      int h,p,q;
      cin >> h >> p >> q;
      p--;
      q--;
      edge[p][h] = q;
      edge[q][h] = p;
    }

    for(int i = 1000; i > 0; i--){
      a = edge[a][i];
    }
    cout << a + 1 << endl;
  }
}