#include #include #define int ll using namespace std; #define rep(i,n) for(int i=0;i=0;i--) #define rng(i,c,n) for(int i=c;i #define _4aNWZeC ios::sync_with_stdio(0),cin.tie(0) using ll=long long; using pii=pair; using vi=vector; void print(){cout<<'\n';} template void print(const h&v,const t&...u){cout<n?0:fact[n]*invfact[k]*invfact[n-k]; } mint f(int n){ return cnk(n,2*n)-cnk(n+1,2*n); } void slv(){ int n,q; cin>>n>>q; vi xs; rep(i,q){ int l,r; cin>>l>>r; l-=1; if((r-l)%2==0){ xs.pb(r-l); } } if(n%2){ print(0); return; } int si=sz(xs); using vm=vec(mint); auto rec=[&](auto self,int l,int r)->vm{ if(l==r){ vm res(xs[l]/2+1); res[0]=1; res[xs[l]/2]=-f(xs[l]/2); return res; } int m=(l+r)/2; return convolution(self(self,l,m),self(self,m+1,r)); }; vm c=rec(rec,0,si-1); mint ans=0; for(int i=0;in) break; // print(i,c[i].val()); ans+=f((n-i*2)/2)*c[i]; } // print(f(xs[0]/2).val()); print(ans.val()); } signed main(){ _4aNWZeC; initfact(); slv(); }