#include <iostream>
#include <algorithm>
#define REP(i, a, n) for(int i = ((int) a); i < ((int) n); i++)
#define fi first
#define se second
using namespace std;
typedef pair<int, int> pii;

int N, M, A, R[2000];
pair<int, pii> L[2000];

int main(void) {
  while(cin >> N >> M >> A, N || M || A) {
    REP(i, 0, M) cin >> L[i].fi >> L[i].se.fi >> L[i].se.se;

    sort(L, L + M);
    reverse(L, L + M);

    REP(i, 1, N + 1) R[i] = i;
    REP(i, 0, M) {
      int tmp = R[L[i].se.fi];
      R[L[i].se.fi] = R[L[i].se.se];
      R[L[i].se.se] = tmp;
    }

    REP(i, 1, N + 1) if(R[i] == A) cout << i << endl;
  }

  return 0;
}