#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
tuple<int, int ,int> d[1000];
signed main() {
  int N, M, A;
  while (cin>>N>>M>>A,N+M+A!=0) {
    for (int i = 0; i < M; i++) {
      int h, p, q; cin>>h>>p>>q;
      d[i] = make_tuple(h,p,q);
    }
    sort(d, d+M);
    reverse(d, d+M);
    int ans = A;
    for (int i = 0; i < M; i++) {
      if (get<1>(d[i]) == ans) {
        ans = get<2>(d[i]); 
      } else if (get<2>(d[i]) == ans) {
        ans = get<1>(d[i]);
      }
    }
    cout << ans << endl;
  }
}

