#include inline long nextInt(void) { long temp; std::cin >> temp; return temp; } int main() { int N, M; int cup[4] = {}; int p, q; int temp; std::cin >> N >> M; cup[N] = 1; for(int i = 0; i < M; ++i) { std::cin >> p >> q; temp = cup[p]; cup[p] = cup[q]; cup[q] = temp; } if( cup[1] == 1 ) std::cout << 1 << std::endl; else if( cup[2] == 1 ) std::cout << 2 << std::endl; else std::cout << 3 << std::endl; return 0; }