n,k=map(int,input().split())
mod=998244353
r=[]
l=[]
for _ in range(k):
  l_,r_=map(int,input().split())
  l.append(l_)
  r.append(r_)
dp=[0]*n
dp[0]=1
dpsum=[0]*n
dpsum[0]=1
for i in range(1,n):
  for j in range(k):
    li=i-r[j]
    ri=i-l[j]
    if ri>=0:
      li=max(li,0)
      dp[i]+=dpsum[ri]-dpsum[li-1]
  dpsum[i]=dpsum[i-1]+dp[i]
print(dp[n-1]%mod)