#include <iostream>
#include <cstring>
using namespace std;
int main(){
  int Amida[1001][101],a,n,m;
  while(cin >> n >> m >> a && n||m||a){
    memset(Amida,0,sizeof(Amida));
    for(int i=0,h,p,q;i<m;i++){
      cin >> h >> p >> q;
      Amida[h][p] = q;
      Amida[h][q] = p;
    }
    for(int i=1000;i>=0;i--){
      if(Amida[i][a] != 0) a = Amida[i][a];
    }
    cout << a << endl;
  }
}