#include using namespace std; #define rep(i,n) for(int (i) = 0 ; (i) < (int)(n) ; (i)++) #define REP(i,a,b) for(int (i) = a ; (int)(i) <= (int)(b) ; (i)++) #define all(n) (n).begin(),(n).end() typedef vector Vi; typedef vector VVi; typedef pair Pii; typedef vector VPii; int main(){ int N; cin >> N; int A[4] = {0,1,0,0}; int M; cin >> M; for(int i = 0 ; i < M ; i++){ int x,y; cin >> x >> y; swap(A[x],A[y]); } cout << find(A,A+4,1) - A << endl; }