#遅延セグ木練習。 #べ、別にRi-Li<=10の制約見落としてたわけじゃないんだからねっ! import sys input = sys.stdin.buffer.readline # ACL for pythonより # https://github.com/shakayami/ACL-for-python/blob/master/lazysegtree.py class lazy_segtree(): def update(self,k):self.d[k]=self.op(self.d[2*k],self.d[2*k+1]) def all_apply(self,k,f): self.d[k]=self.mapping(f,self.d[k]) if (k>i) self.d[p]=x for i in range(1,self.log+1):self.update(p>>i) def get(self,p): assert 0<=p and p>i) return self.d[p] def prod(self,l,r): #[l,r)の取得, [x,x)と取得すると単位元を返すので注意。 assert 0<=l and l<=r and r<=self.n if l==r:return self.e l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<>i) if (((r>>i)<>i) sml,smr=self.e,self.e while(l>=1 r>>=1 return self.op(sml,smr) def all_prod(self):return self.d[1] def apply_point(self,p,f): assert 0<=p and p>i) self.d[p]=self.mapping(f,self.d[p]) for i in range(1,self.log+1):self.update(p>>i) def apply(self,l,r,f): #[l,r)に作用 assert 0<=l and l<=r and r<=self.n if l==r:return l+=self.size r+=self.size for i in range(self.log,0,-1): if (((l>>i)<>i) if (((r>>i)<>i) l2,r2=l,r while(l>=1 r>>=1 l,r=l2,r2 for i in range(1,self.log+1): if (((l>>i)<>i) if (((r>>i)<>i) def max_right(self,l,g): assert 0<=l and l<=self.n assert g(self.e) if l==self.n:return self.n l+=self.size for i in range(self.log,0,-1):self.push(l>>i) sm=self.e while(1): while(i%2==0):l>>=1 if not(g(self.op(sm,self.d[l]))): while(l>i) sm=self.e while(1): r-=1 while(r>1 and (r%2)):r>>=1 if not(g(self.op(self.d[r],sm))): while(r 幅はそのまま if f[1] == 0: return x else: return (x[1] - x[0],x[1]) def composition(f,g): return (f[0]*g[0],(g[1]*f[0]+f[1])%2) def main(): N,Q = map(int,input().split()) S = [(0,1) for _ in range(N)] #値0,幅1が初期値 #E単位元 E = (0,0) G = lazy_segtree(S,operate,E,mapping,composition,(1,0)) for i in range(Q): l,r = map(int,input().split()) l -= 1; r -= 1 G.apply(l,r+1,(1,1)) #1倍して1足す #now = [] #for i in range(N): # now.append(G.get(i)) #print(now) ret = G.prod(0,N) print(ret[0]) if __name__ == '__main__': main()