#include "bits/stdc++.h"
using namespace std;
#define int long long
#define endl '\n'
int mod=1e9+7;
int mod2=998244353;

signed main(){
  while(true){
    int n,m,a;
    cin>>n>>m>>a;
    if(!n&&!m&&!a)break;
    vector<pair<int,int> > v[1001];
    for(int i=0;i<m;i++){
      int h,p,q;
      cin>>h>>p>>q;
      h--;
      v[h].push_back(make_pair(p,q));
    }

    for(int i=1000;i>=0;i--){
      for(int j=0;j<v[i].size();j++){
        if(v[i][j].first==a){
          a=v[i][j].second;
          break;
        }else if(v[i][j].second==a){
          a=v[i][j].first;
          break;
        }
      }
    }
    cout<<a<<endl;
  }
}

