n,k=map(int,input().split())

s=[]

for _ in range(k):
    lr=[int(i) for i in input().split()]
    s+=list(range(lr[0],lr[1]+1))

dp=[0]*(n+1)
dp[1]=1
for i in range(1,n+1):
    for step in s:
        if i+step<=n:
            dp[i+step]=(dp[i+step]+dp[i])%998244353
            
print(dp[-1])
