#include #define int long long using namespace std; signed main(){ int N,Q; cin>>N>>Q; vectorA(Q),B(Q); for(int i=0;i>A[i],A[i]--; for(int i=0;i>B[i],B[i]--; vector>>dp(Q+1); for(int i=Q;i--;){ set>&st=dp[i+1]; auto it=st.upper_bound({A[i],N+2}); if(it==st.begin() || prev(it)->second<=A[i]){ auto itr=st.insert({A[i],A[i]+1}).first; if(itr!=st.begin() && prev(itr)->second==itr->first){ itr=st.insert({prev(itr)->first,itr->second}).first; st.erase(prev(itr)); st.erase(next(itr)); } if(next(itr)!=st.end() && itr->second==next(itr)->first){ itr=st.insert({itr->first,next(itr)->second}).first; st.erase(prev(itr)); st.erase(next(itr)); } } it=st.upper_bound({B[i],N+2}); if(it==st.begin() || prev(it)->second<=B[i]){ auto itr=st.insert({B[i],B[i]+1}).first; if(itr!=st.begin() && prev(itr)->second==itr->first){ itr=st.insert({prev(itr)->first,itr->second}).first; st.erase(prev(itr)); st.erase(next(itr)); } if(next(itr)!=st.end() && itr->second==next(itr)->first){ itr=st.insert({itr->first,next(itr)->second}).first; st.erase(prev(itr)); st.erase(next(itr)); } } if(st.size()){ if(st.begin()->first==0) st.erase(next(st.insert({-1,st.begin()->second}).first)); if(prev(st.end())->second==N) st.erase(prev(st.insert({prev(st.end())->first,N+1}).first)); for(auto[a,b]:st){ if(a+1first==-1) st.erase(prev(st.insert({0,st.begin()->second}).first)); if(prev(st.end())->second==N+1) st.erase(next(st.insert({prev(st.end())->first,N}).first)); } } if(dp[0].count({0,N})) puts("NO"); else{ puts("YES"); int now=0; for(int i=0;isecond<=i){ now=i; break; } } cout<> st=dp[i+1]; set>::iterator it; if((it=st.upper_bound({now,N+2}))==st.begin() || prev(it)->second<=now){ now=now; }else if(now!=0 && (it=st.upper_bound({now-1,N+2}))==st.begin() || prev(it)->second<=now-1){ now=now-1; }else if((it=st.upper_bound({now+1,N+2}))==st.begin() || prev(it)->second<=now+1){ now=now+1; } cout<