#include #include #include #include #include #include #include #include using namespace std; using ll = long long; const ll mod = 1000000007; int n, m; string s, t; string str = "yukicoder"; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n >> m; int pos = n; int num[4] = {0, 1, 2, 3 }; while (m > 0) { int a, b; cin >> a >> b; if (pos == num[a]) pos = num[b]; int temp = 0; temp = num[a]; num[a] = num[b]; num[b] = temp; m--; } cout << pos << endl; return 0; }