import numpy as np
N,K=map(int,input().split())
L=[0]*(N+1)
for i in range(K):
  a,b=map(int,input().split())
  for i in range(a,b+1):
    L[N-i]+=1
qw=[i for i in L]
p=np.poly1d(L)
k=np.poly1d(qw)
ans=0
mod=998244353
s=p.coef
if len(s)>=N:
  ans+=s[-N]

for i in range(N):
  p=p*k
  s=p.coef
  if len(s)>=N:
    ans+=s[-N]
    p=np.poly1d(s[-N:])
  ans%=mod
print(ans)