#include #include using namespace std; int main(void){ bool c[4] = { false }; int n, m, l; cin >> n; c[n] = true; cin >> n; while (n--){ cin >> m >> l; swap(c[m], c[l]); } for (int i = 0; i < 4; i++){ if (c[i])cout << i << endl; } return 0; }