#include <bits/stdc++.h>

using namespace std;

int main(void) {
  int n, m, a;
  while (cin >> n >> m >> a, n) {
    int line[1001][101][2] = {}, h, p, q, d;
    for (int i = 0; i < m; i++) {
      cin >> h >> p >> q;
      d = (p < q) ? 1 : 0;
      line[h][p][d] = 1;
      line[h][q][(d + 1) % 2] = 1;
    }

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

  return 0;
}
