#include using namespace std; using ll=long long; using vb=vector; using vvb=vector; using vd=vector; using vvd=vector; using vi=vector; using vvi=vector; using vl=vector; using vvl=vector; using pll=pair; using tll=tuple; using vs=vector; #define all(a) a.begin(),a.end() #define rall(a) a.rbegin(),a.rend() #define rep(i,n) range(i,0,n) #define range(i,a,n) for(ll i=(a);i<(n);i++) #define LINF ((ll)1ll<<60) #define INF ((int)1<<30) #define EPS (1e-9) #define MOD (1000000007ll) #define fcout(a) cout<ostream&operator<<(ostream&os,pairp){os<<"["<auto&operator<<(ostream&os,vectort){bool a=1; for(auto s:t){os<<(a?"":" ")<void tf(bool b,S t,S f){cout<<(b?t:f)<void puta(T&&t){cout<void puta(H&&h,T&&...t){cout<bool chmax(T&a,T b){if(abool chmin(T&a,T b){if(a>b){a=b; return true;}return false;} /*他のライブラリを入れる場所*/ int main(){ cin.tie(0); ios::sync_with_stdio(false); int n,m; cin>>n>>m; vi a(4,0); a[n]=1; rep(i,m){ int p,q; cin>>p>>q; swap(a[p],a[q]); } cout<<(max_element(all(a))-a.begin())<