#include <iostream>
#include <queue>

using namespace std;

struct bar {
  int height;
  int a;
  int b;
  bool operator<(const bar &right) const {
    return height < right.height;
  }
};

int main() {

  int n, m, a;
  while (cin >> n >> m >> a) {
    if (n == 0 && m == 0 && a == 0) break;
    priority_queue<bar> que;
    while (m--) {
      int h, p, q;
      cin >> h >> p >> q;
      bar b = { h, p, q };
      que.push(b);
    }
    int num = a;
    while (!que.empty()) {
      bar b = que.top(); que.pop();
      if (num == b.a) num = b.b;
      else if (num == b.b) num = b.a;
    }
    cout << num << endl;
  }

  return 0;
}