import sys
input=sys.stdin.readline
n,k=map(int,input().split())
l=[list(map(int,input().split())) for i in range(k)]
mod=998244353
dp=[0]*n
dp[0]=1
dp2=[0,1]

for i in range(1,n):
  for j in range(k):
    dp[i]+=(dp2[max(i-l[j][0]+1,0)]-dp2[max(i-l[j][1],0)])%mod
  dp2.append((dp2[-1]+dp[i])%mod)
print(dp[-1]%mod)