#include <bits/stdc++.h>
using namespace std;

#define int long long

vector<vector<int> > w_line;

signed main() {
  int n, m, a;
  while ( cin >> n >> m >> a, n ) {
    int w_line[1001][101] = {0};
    for ( int i = 0; i < m; i++ ) {
      int h, p, q;
      cin >> h >> p >> q;
      w_line[h][p] = q;
      w_line[h][q] = p;
    }
    
    for ( int i = 1000; i >= 1; i-- ) {
      if ( w_line[i][a] ) a = w_line[i][a];
    }

    cout << a << endl;
  }
  return 0;
}

